Use format macro constants for fprintf and fscanf family functions

This commit is contained in:
Miquel Vidal i Pinyol 2024-04-19 16:04:53 +02:00 committed by Rodrigo Arias
parent 478ed1f5d0
commit 3103018404
14 changed files with 36 additions and 35 deletions

View File

@ -6,6 +6,7 @@
#include <stdio.h>
#include <sys/types.h>
#include <inttypes.h>
extern int is_debug_enabled;

View File

@ -59,7 +59,7 @@ cparse(struct clkoff *table, FILE *file)
if (buf[0] == '\n')
continue;
int ret = sscanf(buf, "%ld %s %lf %lf %lf",
int ret = sscanf(buf, "%" SCNi64 "%s %lf %lf %lf",
&e.index, e.name,
&e.median, &e.mean, &e.stdev);

View File

@ -302,7 +302,7 @@ model_nanos6_breakdown_finish(struct emu *emu,
struct prf *prf = pvt_get_prf(bemu->pvt);
for (int64_t row = 0; row < bemu->nphycpus; row++) {
char name[128];
if (snprintf(name, 128, "~CPU %4ld", bemu->nphycpus - row) >= 128) {
if (snprintf(name, 128, "~CPU %4" PRIi64, bemu->nphycpus - row) >= 128) {
err("label too long");
return -1;
}

View File

@ -23,7 +23,7 @@ emit(struct model *model, struct player *player)
struct emu_ev *ev = player_ev(player);
struct stream *stream = player_stream(player);
printf("%10ld %c%c%c %s ",
printf("%10" PRIi64 " %c%c%c %s ",
ev->rclock,
ev->m,
ev->c,

View File

@ -71,7 +71,7 @@ find_prv_chan(struct prv *prv, long id)
static void
write_line(struct prv *prv, long row_base1, long type, long value)
{
fprintf(prv->file, "2:0:1:1:%ld:%ld:%ld:%ld\n",
fprintf(prv->file, "2:0:1:1:%ld:%" PRIi64 ":%ld:%ld\n",
row_base1, prv->time, type, value);
}

View File

@ -68,7 +68,7 @@ value_str(struct value a)
ret = snprintf(buf, n, "{NULL}");
break;
case VALUE_INT64:
ret = snprintf(buf, n, "{int64_t %ld}", a.i);
ret = snprintf(buf, n, "{int64_t %" PRIi64 "}", a.i);
break;
case VALUE_DOUBLE:
ret = snprintf(buf, n, "{double %e}", a.d);

View File

@ -35,13 +35,13 @@ main(void)
die("fopen failed:");
/* Ensure non-zero for A (first event) */
fprintf(f, "grep ':%ld:%d:[^0][0-9]*$' ovni/nanos6-breakdown.prv\n",
fprintf(f, "grep ':%" PRIi64 ":%d:[^0][0-9]*$' ovni/nanos6-breakdown.prv\n",
get_delta(), PRV_NANOS6_BREAKDOWN);
instr_nanos6_worker_loop_enter();
/* And for B */
fprintf(f, "grep ':%ld:%d:[^0][0-9]*$' ovni/nanos6-breakdown.prv\n",
fprintf(f, "grep ':%" PRIi64 ":%d:[^0][0-9]*$' ovni/nanos6-breakdown.prv\n",
get_delta(), PRV_NANOS6_BREAKDOWN);
instr_nanos6_worker_loop_exit();

View File

@ -34,16 +34,16 @@ main(void)
int type = PRV_NANOS6_SUBSYSTEM;
int64_t t = get_delta();
int value = ST_WORKER_LOOP;
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, type, value);
instr_nanos6_worker_loop_exit();
/* Also test when exitting the stacked subsystem */
t = get_delta();
value = 0;
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, type, value);
fclose(f);

View File

@ -29,21 +29,21 @@ main(void)
instr_nanos6_absorbing();
/* Ensure the only row in breakdown is in absorbing */
fprintf(f, "grep '1:%ld:%d:%d$' ovni/nanos6-breakdown.prv\n",
fprintf(f, "grep '1:%" PRIi64 ":%d:%d$' ovni/nanos6-breakdown.prv\n",
get_delta(), type, ST_ABSORBING);
/* Set state to Resting */
instr_nanos6_resting();
/* Ensure the only row in breakdown is in Resting */
fprintf(f, "grep '1:%ld:%d:%d$' ovni/nanos6-breakdown.prv\n",
fprintf(f, "grep '1:%" PRIi64 ":%d:%d$' ovni/nanos6-breakdown.prv\n",
get_delta(), type, ST_RESTING);
instr_nanos6_progressing();
/* Now the state must follow the subsystem, which should be
* sponge mode */
fprintf(f, "grep '1:%ld:%d:%d$' ovni/nanos6-breakdown.prv\n",
fprintf(f, "grep '1:%" PRIi64 ":%d:%d$' ovni/nanos6-breakdown.prv\n",
get_delta(), type, ST_SPONGE);
fclose(f);

View File

@ -25,15 +25,15 @@ main(void)
int type = PRV_NANOS6_SUBSYSTEM;
int64_t t = get_delta();
int value = ST_SPONGE;
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, type, value);
instr_nanos6_sponge_exit();
t = get_delta();
value = 0;
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, type, value);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, type, value);
fclose(f);

View File

@ -41,14 +41,14 @@ main(void)
/* Check the task type */
int prvtype = PRV_NANOS6_TYPE;
int64_t t = get_delta();
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, prvtype, gid);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, prvtype, gid);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, prvtype, gid);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, prvtype, gid);
/* Check the rank */
prvtype = PRV_NANOS6_RANK;
int rank = 0 + 1; /* Starts at one */
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, prvtype, rank);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, prvtype, rank);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, prvtype, rank);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, prvtype, rank);
fclose(f);
/* Exit from tasks and subsystem */

View File

@ -39,20 +39,20 @@ main(void)
/* Check the task type */
int prvtype = PRV_NOSV_TYPE;
int64_t t = get_delta();
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, prvtype, gid);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, prvtype, gid);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, prvtype, gid);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, prvtype, gid);
/* Check the task appid */
prvtype = PRV_NOSV_APPID;
int appid = 1; /* Starts at one */
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, prvtype, appid);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, prvtype, appid);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, prvtype, appid);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, prvtype, appid);
/* Check the rank */
prvtype = PRV_NOSV_RANK;
int rank = 0 + 1; /* Starts at one */
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", t, prvtype, rank);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", t, prvtype, rank);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", t, prvtype, rank);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", t, prvtype, rank);
fclose(f);
/* Exit from tasks and subsystem */

View File

@ -40,22 +40,22 @@ main(void)
* the "Task: In body" state */
int prvtype = PRV_NOSV_SUBSYSTEM;
int st = ST_TASK_BODY;
fprintf(f, "grep ':%ld:%d:%d$' ovni/thread.prv\n", get_delta(), prvtype, st);
fprintf(f, "grep ':%ld:%d:%d$' ovni/cpu.prv\n", get_delta(), prvtype, st);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/thread.prv\n", get_delta(), prvtype, st);
fprintf(f, "grep ':%" PRIi64 ":%d:%d$' ovni/cpu.prv\n", get_delta(), prvtype, st);
instr_nosv_submit_enter(); /* Blocking submit */
instr_nosv_task_pause(1, 0);
/* Should be left in the submit state, so no state transition in
* subsystems view */
fprintf(f, "! grep ':%ld:%d:[0-9]*$' ovni/thread.prv\n", get_delta(), prvtype);
fprintf(f, "! grep ':%ld:%d:[0-9]*$' ovni/cpu.prv\n", get_delta(), prvtype);
fprintf(f, "! grep ':%" PRIi64 ":%d:[0-9]*$' ovni/thread.prv\n", get_delta(), prvtype);
fprintf(f, "! grep ':%" PRIi64 ":%d:[0-9]*$' ovni/cpu.prv\n", get_delta(), prvtype);
/* But the task state must be set to pause, so the task id
* must be null */
prvtype = PRV_NOSV_TASKID;
fprintf(f, "grep ':%ld:%d:0$' ovni/thread.prv\n", get_delta(), prvtype);
fprintf(f, "grep ':%ld:%d:0$' ovni/cpu.prv\n", get_delta(), prvtype);
fprintf(f, "grep ':%" PRIi64 ":%d:0$' ovni/thread.prv\n", get_delta(), prvtype);
fprintf(f, "grep ':%" PRIi64 ":%d:0$' ovni/cpu.prv\n", get_delta(), prvtype);
instr_nosv_submit_exit();
instr_nosv_task_resume(1, 0);

View File

@ -116,7 +116,7 @@ count_prv_lines(char *fpath, int64_t time, int row0, long type, long value)
int64_t ftime;
long frow1, ftype, fvalue;
int ret = sscanf(line, "2:0:1:1:%ld:%ld:%ld:%ld",
int ret = sscanf(line, "2:0:1:1:%ld:%" SCNi64 ":%ld:%ld",
&frow1, &ftime, &ftype, &fvalue);
if (ret != 4)