Use snprintf in client/deps

This commit is contained in:
Doridian 2022-06-10 12:29:18 -07:00
commit fe4599fb14
7 changed files with 35 additions and 35 deletions

View file

@ -173,8 +173,8 @@ crack_states_thread(void *x) {
char progress_text[80];
char keystr[19];
sprintf(keystr, "%012" PRIX64 " ", key);
sprintf(progress_text, "Brute force phase completed. Key found: " _GREEN_("%s"), keystr);
snprintf(keystr, sizeof(keystr), "%012" PRIX64 " ", key);
snprintf(progress_text, sizeof(progress_text), "Brute force phase completed. Key found: " _GREEN_("%s"), keystr);
hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, 0.0, 0);
break;
} else if (keys_found) {
@ -182,7 +182,7 @@ crack_states_thread(void *x) {
} else {
if (!thread_arg->silent) {
char progress_text[80];
sprintf(progress_text, "Brute force phase: %6.02f%%\t", 100.0 * (float)num_keys_tested / (float)(thread_arg->maximum_states));
snprintf(progress_text, sizeof(progress_text), "Brute force phase: %6.02f%%\t", 100.0 * (float)num_keys_tested / (float)(thread_arg->maximum_states));
float remaining_bruteforce = thread_arg->nonces[thread_arg->best_first_bytes[0]].expected_num_brute_force - (float)num_keys_tested / 2;
hardnested_print_progress(thread_arg->num_acquired_nonces, progress_text, remaining_bruteforce, 5000);
}

View file

@ -200,7 +200,7 @@ static inline uint32_t count_states(uint32_t *bitset) {
static void write_bitflips_file(odd_even_t odd_even, uint16_t bitflip, int sum_a0, uint32_t *bitset, uint32_t count) {
char filename[80];
sprintf(filename, "bitflip_%d_%03" PRIx16 "_sum%d_states.bin", odd_even, bitflip, sum_a0);
snprintf(filename, sizeof(filename), "bitflip_%d_%03" PRIx16 "_sum%d_states.bin", odd_even, bitflip, sum_a0);
FILE *outfile = fopen(filename, "wb");
fwrite(&count, 1, sizeof(count), outfile);
fwrite(bitset, 1, sizeof(uint32_t) * (1 << 19), outfile);

View file

@ -215,7 +215,7 @@ const char *luaO_pushvfstring(lua_State *L, const char *fmt, va_list argp) {
}
case 'p': {
char buff[4 * sizeof(void *) + 8]; /* should be enough space for a `%p' */
int l = sprintf(buff, "%p", va_arg(argp, void *));
int l = snprintf(buff, sizeof(buff), "%p", va_arg(argp, void *));
pushstr(L, buff, l);
break;
}

View file

@ -879,9 +879,9 @@ static void addquoted(lua_State *L, luaL_Buffer *b, int arg) {
} else if (*s == '\0' || iscntrl(uchar(*s))) {
char buff[10];
if (!isdigit(uchar(*(s + 1))))
sprintf(buff, "\\%d", (int)uchar(*s));
snprintf(buff, sizeof(buff), "\\%d", (int)uchar(*s));
else
sprintf(buff, "\\%03d", (int)uchar(*s));
snprintf(buff, sizeof(buff), "\\%03d", (int)uchar(*s));
luaL_addstring(b, buff);
} else
luaL_addchar(b, *s);
@ -947,7 +947,7 @@ static int str_format(lua_State *L) {
strfrmt = scanformat(L, strfrmt, form);
switch (*strfrmt++) {
case 'c': {
nb = sprintf(buff, form, luaL_checkint(L, arg));
nb = snprintf(buff, MAX_ITEM, form, luaL_checkint(L, arg));
break;
}
case 'd':
@ -958,7 +958,7 @@ static int str_format(lua_State *L) {
luaL_argcheck(L, -1 < diff && diff < 1, arg,
"not a number in proper range");
addlenmod(form, LUA_INTFRMLEN);
nb = sprintf(buff, form, ni);
nb = snprintf(buff, MAX_ITEM, form, ni);
break;
}
case 'o':
@ -971,7 +971,7 @@ static int str_format(lua_State *L) {
luaL_argcheck(L, -1 < diff && diff < 1, arg,
"not a non-negative number in proper range");
addlenmod(form, LUA_INTFRMLEN);
nb = sprintf(buff, form, ni);
nb = snprintf(buff, MAX_ITEM, form, ni);
break;
}
case 'e':
@ -984,7 +984,7 @@ static int str_format(lua_State *L) {
case 'g':
case 'G': {
addlenmod(form, LUA_FLTFRMLEN);
nb = sprintf(buff, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
nb = snprintf(buff, MAX_ITEM, form, (LUA_FLTFRM_T)luaL_checknumber(L, arg));
break;
}
case 'q': {
@ -1000,7 +1000,7 @@ static int str_format(lua_State *L) {
luaL_addvalue(&b);
break;
} else {
nb = sprintf(buff, form, s);
nb = snprintf(buff, MAX_ITEM, form, s);
lua_pop(L, 1); /* remove result from 'luaL_tolstring' */
break;
}

View file

@ -408,7 +408,7 @@
*/
#define LUA_NUMBER_SCAN "%lf"
#define LUA_NUMBER_FMT "%.14g"
#define lua_number2str(s,n) sprintf((s), LUA_NUMBER_FMT, (n))
#define lua_number2str(s,l,n) snprintf((s), (l), LUA_NUMBER_FMT, (n))
#define LUAI_MAXNUMBER2STR 32 /* 16 digits, sign, point, and \0 */

View file

@ -49,7 +49,7 @@ int luaV_tostring(lua_State *L, StkId obj) {
else {
char s[LUAI_MAXNUMBER2STR];
lua_Number n = nvalue(obj);
int l = lua_number2str(s, n);
int l = lua_number2str(s, sizeof(s), n);
setsvalue2s(L, obj, luaS_newlstr(L, s, l));
return 1;
}

View file

@ -107,7 +107,7 @@ char *mtostr(const model_t *model) {
checkstr = ptostr(model->check, P_RTJUST, 4);
magicstr = ptostr(model->magic, P_RTJUST, 4);
sprintf(strbuf, "%lu", plen(model->spoly));
snprintf(strbuf, sizeof(strbuf), "%lu", plen(model->spoly));
size =
82
+ strlen(strbuf)
@ -120,8 +120,8 @@ char *mtostr(const model_t *model) {
+ (magicstr && *magicstr ? strlen(magicstr) : 6)
+ (model->name && *model->name ? 2 + strlen(model->name) : 6);
if ((string = calloc(size, sizeof(uint8_t)))) {
sprintf(strbuf, "\"%s\"", model->name);
sprintf(string,
snprintf(strbuf, sizeof(strbuf), "\"%s\"", model->name);
snprintf(string, size * sizeof(uint8_t),
"width=%lu "
"poly=0x%s "
"init=0x%s "