Skip to content

Commit

Permalink
snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
KrystalDelusion committed Aug 4, 2024
1 parent 5251190 commit dc4a328
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
36 changes: 18 additions & 18 deletions libs/fst/fstapi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ void fstWriterClose(void *ctx)
fflush(xc->handle);

#ifndef __MINGW32__
sprintf(fnam, "%s.hier", xc->filename);
snprintf(fnam, sizeof(fnam), "%s.hier", xc->filename);

Check warning on line 1994 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-10)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 1994 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 1994 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
unlink(fnam);
free(fnam);
#endif
Expand Down Expand Up @@ -2616,7 +2616,7 @@ fstEnumHandle fstWriterCreateEnumTable(void *ctx, const char *name, uint32_t ele
uint32_t i;

name_len = strlen(name);
elem_count_len = sprintf(elem_count_buf, "%" PRIu32, elem_count);
elem_count_len = snprintf(elem_count_buf, sizeof(elem_count_buf), "%" PRIu32, elem_count);

literal_lens = (unsigned int *)calloc(elem_count, sizeof(unsigned int));
val_lens = (unsigned int *)calloc(elem_count, sizeof(unsigned int));
Expand Down Expand Up @@ -3594,7 +3594,7 @@ static int fstReaderRecreateHierFile(struct fstReaderContext *xc)
htyp = xc->contains_hier_section_lz4duo ? FST_BL_HIER_LZ4DUO : FST_BL_HIER_LZ4;
}

sprintf(fnam, "%s.hier_%d_%p", xc->filename, getpid(), (void *)xc);
snprintf(fnam, sizeof(fnam), "%s.hier_%d_%p", xc->filename, getpid(), (void *)xc);

Check warning on line 3597 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-10)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 3597 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 3597 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
fstReaderFseeko(xc, xc->f, xc->hier_pos, SEEK_SET);
uclen = fstReaderUint64(xc->f);
#ifndef __MINGW32__
Expand Down Expand Up @@ -4241,7 +4241,7 @@ int fstReaderInit(struct fstReaderContext *xc)

hf = (char *)calloc(1, flen + 16 + 32 + 1);

sprintf(hf, "%s.upk_%d_%p", xc->filename, getpid(), (void *)xc);
snprintf(hf, sizeof(hf), "%s.upk_%d_%p", xc->filename, getpid(), (void *)xc);

Check warning on line 4244 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-10)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 4244 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 4244 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]
fcomp = fopen(hf, "w+b");
if (!fcomp) {
fcomp = tmpfile_open(&xc->f_nam);
Expand Down Expand Up @@ -4799,21 +4799,21 @@ int fstReaderIterBlocks2(void *ctx,

if (beg_tim) {
if (dumpvars_state == 1) {
wx_len = sprintf(wx_buf, "$end\n");
wx_len = snprintf(wx_buf, 6, "$end\n");
fstWritex(xc, wx_buf, wx_len);
dumpvars_state = 2;
}
wx_len = sprintf(wx_buf, "#%" PRIu64 "\n", beg_tim);
wx_len = snprintf(wx_buf, 20, "#%" PRIu64 "\n", beg_tim);
fstWritex(xc, wx_buf, wx_len);
if (!dumpvars_state) {
wx_len = sprintf(wx_buf, "$dumpvars\n");
wx_len = snprintf(wx_buf, 11, "$dumpvars\n");
fstWritex(xc, wx_buf, wx_len);
dumpvars_state = 1;
}
}
if ((xc->num_blackouts) && (cur_blackout != xc->num_blackouts)) {
if (beg_tim == xc->blackout_times[cur_blackout]) {
wx_len = sprintf(wx_buf, "$dump%s $end\n",
wx_len = snprintf(wx_buf, 16, "$dump%s $end\n",
(xc->blackout_activity[cur_blackout++]) ? "on" : "off");
fstWritex(xc, wx_buf, wx_len);
}
Expand Down Expand Up @@ -4914,7 +4914,7 @@ int fstReaderIterBlocks2(void *ctx,
clone_d[j] = srcdata[7 - j];
}
}
sprintf((char *)xc->temp_signal_value_buf, "%.16g", d);
snprintf((char *)xc->temp_signal_value_buf, 32, "%.16g", d);
value_change_callback(user_callback_data_pointer, beg_tim, idx + 1,
xc->temp_signal_value_buf);
}
Expand All @@ -4936,7 +4936,7 @@ int fstReaderIterBlocks2(void *ctx,
}

fstVcdID(vcdid_buf, idx + 1);
wx_len = sprintf(wx_buf, "r%.16g %s\n", d, vcdid_buf);
wx_len = snprintf(wx_buf, sizeof(wx_buf), "r%.16g %s\n", d, vcdid_buf);
fstWritex(xc, wx_buf, wx_len);
}
}
Expand Down Expand Up @@ -5179,21 +5179,21 @@ int fstReaderIterBlocks2(void *ctx,
}

if (dumpvars_state == 1) {
wx_len = sprintf(wx_buf, "$end\n");
wx_len = snprintf(wx_buf, 6, "$end\n");
fstWritex(xc, wx_buf, wx_len);
dumpvars_state = 2;
}
wx_len = sprintf(wx_buf, "#%" PRIu64 "\n", time_table[i]);
wx_len = snprintf(wx_buf, 20, "#%" PRIu64 "\n", time_table[i]);
fstWritex(xc, wx_buf, wx_len);
if (!dumpvars_state) {
wx_len = sprintf(wx_buf, "$dumpvars\n");
wx_len = snprintf(wx_buf, 11, "$dumpvars\n");
fstWritex(xc, wx_buf, wx_len);
dumpvars_state = 1;
}

if ((xc->num_blackouts) && (cur_blackout != xc->num_blackouts)) {
if (time_table[i] == xc->blackout_times[cur_blackout]) {
wx_len = sprintf(wx_buf, "$dump%s $end\n",
wx_len = snprintf(wx_buf, 16, "$dump%s $end\n",
(xc->blackout_activity[cur_blackout++]) ? "on" : "off");
fstWritex(xc, wx_buf, wx_len);
}
Expand Down Expand Up @@ -5407,7 +5407,7 @@ int fstReaderIterBlocks2(void *ctx,
clone_d[j] = srcdata[7 - j];
}
}
sprintf((char *)xc->temp_signal_value_buf, "%.16g", d);
snprintf((char *)xc->temp_signal_value_buf, 32, "%.16g", d);
value_change_callback(user_callback_data_pointer, time_table[i], idx + 1,
xc->temp_signal_value_buf);
}
Expand All @@ -5427,7 +5427,7 @@ int fstReaderIterBlocks2(void *ctx,
}
}

wx_len = sprintf(wx_buf, "r%.16g", d);
wx_len = snprintf(wx_buf, sizeof(wx_buf), "r%.16g", d);
fstWritex(xc, wx_buf, wx_len);
}
}
Expand Down Expand Up @@ -5523,7 +5523,7 @@ static char *fstExtractRvatDataFromFrame(struct fstReaderContext *xc, fstHandle
}
}

sprintf((char *)buf, "%.16g", d);
snprintf((char *)buf, 32, "%.16g", d);
}
}

Expand Down Expand Up @@ -6045,7 +6045,7 @@ char *fstReaderGetValueFromHandleAtTime(void *ctx, uint64_t tim, fstHandle facid
}
}

sprintf(buf, "r%.16g", d);
snprintf(buf, sizeof(buf), "r%.16g", d);

Check warning on line 6048 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-10)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 6048 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc-10)

‘%.16g’ directive output may be truncated writing between 1 and 23 bytes into a region of size 7 [-Wformat-truncation=]

Check warning on line 6048 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 6048 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

‘%.16g’ directive output may be truncated writing between 1 and 23 bytes into a region of size 7 [-Wformat-truncation=]

Check warning on line 6048 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

argument to ‘sizeof’ in ‘int snprintf(char*, size_t, const char*, ...)’ call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

Check warning on line 6048 in libs/fst/fstapi.cc

View workflow job for this annotation

GitHub Actions / test-compile (ubuntu-latest, gcc)

‘%.16g’ directive output may be truncated writing between 1 and 23 bytes into a region of size 7 [-Wformat-truncation=]
return (buf);
}
} else {
Expand Down
4 changes: 2 additions & 2 deletions libs/minisat/System.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static inline int memReadStat(int field)
pid_t pid = getpid();
int value;

sprintf(name, "/proc/%d/statm", pid);
snprintf(name, 256, "/proc/%d/statm", pid);
FILE* in = fopen(name, "rb");
if (in == NULL) return 0;

Expand All @@ -60,7 +60,7 @@ static inline int memReadPeak(void)
char name[256];
pid_t pid = getpid();

sprintf(name, "/proc/%d/status", pid);
snprintf(name, 256, "/proc/%d/status", pid);
FILE* in = fopen(name, "rb");
if (in == NULL) return 0;

Expand Down

0 comments on commit dc4a328

Please sign in to comment.