No need to store unique ID in VM.
已通過所有檢查
The build was successful.

This commit is contained in:
Rafal Kupiec 2018-09-05 18:24:34 +02:00
父節點 ae79cb57de
當前提交 404f5a2688
簽署人: belliash
GPG 金鑰 ID: 4E829243E0CFE6B4
共有 2 個檔案被更改,包括 4 行新增6 行删除

查看文件

@ -1116,8 +1116,6 @@ PH7_PRIVATE sxi32 PH7_VmMakeReady(
return rc;
}
}
/* Random number between 0 and 1023 used to generate unique ID */
pVm->unique_id = PH7_VmRandomNum(&(*pVm)) & 1023;
/* VM is ready for bytecode execution */
return SXRET_OK;
}
@ -8220,10 +8218,13 @@ static int vm_builtin_uniqid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
const char *zPrefix;
SHA1Context sCtx;
char zRandom[7];
sxu32 uniqueid;
int nPrefix;
int entropy;
/* Generate a random string first */
PH7_VmRandomString(pVm, zRandom, (int)sizeof(zRandom));
/* Generate a random number between 0 and 1023 */
uniqueid = PH7_VmRandomNum(&(*pVm)) & 1023;
/* Initialize fields */
zPrefix = 0;
nPrefix = 0;
@ -8241,11 +8242,9 @@ static int vm_builtin_uniqid(ph7_context *pCtx, int nArg, ph7_value **apArg) {
SHA1Update(&sCtx, (const unsigned char *)zPrefix, (unsigned int)nPrefix);
}
/* Append the random ID */
SHA1Update(&sCtx, (const unsigned char *)&pVm->unique_id, sizeof(int));
SHA1Update(&sCtx, (const unsigned char *)&uniqueid, sizeof(int));
/* Append the random string */
SHA1Update(&sCtx, (const unsigned char *)zRandom, sizeof(zRandom));
/* Increment the number */
pVm->unique_id++;
SHA1Final(&sCtx, zDigest);
/* Hexify the digest */
sUniq.pCtx = pCtx;

查看文件

@ -1233,7 +1233,6 @@ struct ph7_vm {
int nExceptDepth; /* Exception depth */
int closure_cnt; /* Loaded closures counter */
int json_rc; /* JSON return status [refer to json_encode()/json_decode()]*/
sxu32 unique_id; /* Random number used to generate unique ID [refer to uniqid() for more info]*/
sxu32 nOutputLen; /* Total number of generated output */
ph7_output_consumer sVmConsumer; /* Registered output consumer callback */
int iAssertFlags; /* Assertion flags */