Skip to content

Commit 327f550

Browse files
author
Denys Vlasenko
committed
Use unsigned printf/scanf conversion where more appropriate
Signed-off-by: Denys Vlasenko <[email protected]>
1 parent 9b2a9f0 commit 327f550

File tree

18 files changed

+37
-37
lines changed

18 files changed

+37
-37
lines changed

Diff for: coreutils/cal.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ int cal_main(int argc UNUSED_PARAM, char **argv)
165165
char lineout[30];
166166

167167
day_array(month, year, dp);
168-
len = sprintf(lineout, "%s %d", month_names[month - 1], year);
168+
len = sprintf(lineout, "%s %u", month_names[month - 1], year);
169169
printf("%*s%s\n%s\n",
170170
((7*julian + WEEK_LEN) - len) / 2, "",
171171
lineout, day_headings);

Diff for: coreutils/sum.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ static unsigned sum_file(const char *file, unsigned type)
7070
if (type >= SUM_SYSV) {
7171
r = (s & 0xffff) + ((s & 0xffffffff) >> 16);
7272
s = (r & 0xffff) + (r >> 16);
73-
printf("%d %llu %s\n", s, (total_bytes + 511) / 512, file);
73+
printf("%u %llu %s\n", s, (total_bytes + 511) / 512, file);
7474
} else
75-
printf("%05d %5llu %s\n", s, (total_bytes + 1023) / 1024, file);
75+
printf("%05u %5llu %s\n", s, (total_bytes + 1023) / 1024, file);
7676
return 1;
7777
#undef buf
7878
}

Diff for: e2fsprogs/old_e2fsprogs/mke2fs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static void test_disk(ext2_filsys fs, badblocks_list *bb_list)
239239
errcode_t retval;
240240
char buf[1024];
241241

242-
sprintf(buf, "badblocks -b %d %s%s%s %d", fs->blocksize,
242+
sprintf(buf, "badblocks -b %u %s%s%s %d", fs->blocksize,
243243
quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
244244
fs->device_name, fs->super->s_blocks_count);
245245
mke2fs_verbose("Running command: %s\n", buf);

Diff for: e2fsprogs/old_e2fsprogs/tune2fs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ int tune2fs_main(int argc, char **argv)
607607
if (e_flag) {
608608
sb->s_errors = errors;
609609
ext2fs_mark_super_dirty(fs);
610-
printf("Setting error behavior to %d\n", errors);
610+
printf("Setting error behavior to %u\n", errors);
611611
}
612612
if (g_flag) {
613613
sb->s_def_resgid = resgid;

Diff for: e2fsprogs/old_e2fsprogs/util.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void make_journal_blocks(ext2_filsys fs, int journal_size, int journal_flags, in
239239
return;
240240
}
241241
if (!quiet)
242-
printf("Creating journal (%ld blocks): ", journal_blocks);
242+
printf("Creating journal (%lu blocks): ", journal_blocks);
243243
fflush(stdout);
244244
retval = ext2fs_add_journal_inode(fs, journal_blocks,
245245
journal_flags);

Diff for: editors/patch_bbox.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,8 @@ int patch_main(int argc UNUSED_PARAM, char **argv)
188188
unsigned src_last_line = 1;
189189
unsigned dst_last_line = 1;
190190

191-
if ((sscanf(patch_line, "@@ -%d,%d +%d,%d", &src_beg_line, &src_last_line, &dst_beg_line, &dst_last_line) < 3)
192-
&& (sscanf(patch_line, "@@ -%d +%d,%d", &src_beg_line, &dst_beg_line, &dst_last_line) < 2)
191+
if ((sscanf(patch_line, "@@ -%u,%u +%u,%u", &src_beg_line, &src_last_line, &dst_beg_line, &dst_last_line) < 3)
192+
&& (sscanf(patch_line, "@@ -%u +%u,%u", &src_beg_line, &dst_beg_line, &dst_last_line) < 2)
193193
) {
194194
/* No more hunks for this file */
195195
break;

Diff for: miscutils/hdparm.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -465,14 +465,14 @@ static void on_off(int value)
465465
static void print_flag_on_off(int get_arg, const char *s, unsigned long arg)
466466
{
467467
if (get_arg) {
468-
printf(" setting %s to %ld", s, arg);
468+
printf(" setting %s to %lu", s, arg);
469469
on_off(arg);
470470
}
471471
}
472472

473473
static void print_value_on_off(const char *str, unsigned long argp)
474474
{
475-
printf(" %s\t= %2ld", str, argp);
475+
printf(" %s\t= %2lu", str, argp);
476476
on_off(argp != 0);
477477
}
478478

@@ -1509,7 +1509,7 @@ static void bus_state_value(unsigned value)
15091509
else if (value == BUSSTATE_TRISTATE)
15101510
printf(" (tristate)\n");
15111511
else
1512-
printf(" (unknown: %d)\n", value);
1512+
printf(" (unknown: %u)\n", value);
15131513
}
15141514
#endif
15151515

@@ -1589,7 +1589,7 @@ static void interpret_xfermode(unsigned xfermode)
15891589
static void print_flag(int flag, const char *s, unsigned long value)
15901590
{
15911591
if (flag)
1592-
printf(" setting %s to %ld\n", s, value);
1592+
printf(" setting %s to %lu\n", s, value);
15931593
}
15941594

15951595
static void process_dev(char *devname)

Diff for: networking/arp.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,12 @@ static int arp_show(char *name)
459459
arp_disp(hostname, ip, type, flags, hwa, mask, dev);
460460
}
461461
if (option_mask32 & ARP_OPT_v)
462-
printf("Entries: %d\tSkipped: %d\tFound: %d\n",
462+
printf("Entries: %u\tSkipped: %u\tFound: %u\n",
463463
entries, entries - shown, shown);
464464

465465
if (!shown) {
466466
if (hw_set || host || device[0])
467-
printf("No match found in %d entries\n", entries);
467+
printf("No match found in %u entries\n", entries);
468468
}
469469
if (ENABLE_FEATURE_CLEAN_UP) {
470470
free((char*)host);

Diff for: networking/netstat.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ typedef enum {
125125
*/
126126
#define ADDR_WIDE 51 /* INET6_ADDRSTRLEN + 5 for the port number */
127127
#if ENABLE_FEATURE_NETSTAT_WIDE
128-
# define FMT_NET_CONN_DATA "%s %6ld %6ld %-*s %-*s %-12s"
128+
# define FMT_NET_CONN_DATA "%s %6lu %6lu %-*s %-*s %-12s"
129129
# define FMT_NET_CONN_HEADER "\nProto Recv-Q Send-Q %-*s %-*s State %s\n"
130130
#else
131-
# define FMT_NET_CONN_DATA "%s %6ld %6ld %-23s %-23s %-12s"
131+
# define FMT_NET_CONN_DATA "%s %6lu %6lu %-23s %-23s %-12s"
132132
# define FMT_NET_CONN_HEADER "\nProto Recv-Q Send-Q %-23s %-23s State %s\n"
133133
#endif
134134

@@ -403,7 +403,7 @@ static int scan_inet_proc_line(struct inet_params *param, char *line)
403403
"%*d: %32[0-9A-Fa-f]:%X "
404404
"%32[0-9A-Fa-f]:%X %X "
405405
"%lX:%lX %*X:%*X "
406-
"%*X %d %*d %ld ",
406+
"%*X %d %*d %lu ",
407407
local_addr, &param->local_port,
408408
rem_addr, &param->rem_port, &param->state,
409409
&param->txq, &param->rxq,
@@ -611,7 +611,7 @@ static int FAST_FUNC unix_do_one(char *line)
611611
strcat(ss_flags, "N ");
612612
strcat(ss_flags, "]");
613613

614-
printf("%-5s %-6ld %-11s %-10s %-13s %6lu ",
614+
printf("%-5s %-6lu %-11s %-10s %-13s %6lu ",
615615
ss_proto, refcnt, ss_flags, ss_type, ss_state, inode
616616
);
617617

Diff for: networking/pscan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ int pscan_main(int argc UNUSED_PARAM, char **argv)
157157
}
158158
if (ENABLE_FEATURE_CLEAN_UP) free(lsap);
159159

160-
printf("%d closed, %d open, %d timed out (or blocked) ports\n",
160+
printf("%u closed, %u open, %u timed out (or blocked) ports\n",
161161
closed_ports,
162162
open_ports,
163163
nports - (closed_ports + open_ports));

Diff for: procps/pgrep.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ static void act(unsigned pid, char *cmd, int signo)
6565
{
6666
if (pgrep) {
6767
if (option_mask32 & (1 << OPTBIT_L)) /* OPT_LIST */
68-
printf("%d %s\n", pid, cmd);
68+
printf("%u %s\n", pid, cmd);
6969
else
70-
printf("%d\n", pid);
70+
printf("%u\n", pid);
7171
} else
7272
kill(pid, signo);
7373
}

Diff for: procps/top.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ static NOINLINE void display_process_list(int lines_rem, int scr_width)
677677
if (s->vsz >= 100000)
678678
sprintf(vsz_str_buf, "%6ldm", s->vsz/1024);
679679
else
680-
sprintf(vsz_str_buf, "%7ld", s->vsz);
680+
sprintf(vsz_str_buf, "%7lu", s->vsz);
681681
/* PID PPID USER STAT VSZ %VSZ [%CPU] COMMAND */
682682
col = snprintf(line_buf, scr_width,
683683
"\n" "%5u%6u %-8.8s %s%s" FMT

Diff for: sysklogd/logread.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ int logread_main(int argc UNUSED_PARAM, char **argv)
126126
shbuf_data = shbuf->data; /* pointer! */
127127

128128
if (DEBUG)
129-
printf("cur:%d tail:%i size:%i\n",
129+
printf("cur:%u tail:%u size:%u\n",
130130
cur, shbuf_tail, shbuf_size);
131131

132132
if (!follow) {

Diff for: util-linux/fdformat.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int fdformat_main(int argc UNUSED_PARAM, char **argv)
7272
/* original message was: "Could not determine current format type" */
7373
xioctl(fd, FDGETPRM, &param);
7474

75-
printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB\n",
75+
printf("%s-sided, %u tracks, %u sec/track. Total capacity %d kB\n",
7676
(param.head == 2) ? "Double" : "Single",
7777
param.track, param.sect, param.size >> 1);
7878

Diff for: util-linux/fsck_minix.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ static void get_inode_common(unsigned nr, uint16_t i_mode)
686686
total++;
687687
if (!inode_count[nr]) {
688688
if (!inode_in_use(nr)) {
689-
printf("Inode %d is marked as 'unused', but it is used "
689+
printf("Inode %u is marked as 'unused', but it is used "
690690
"for file '%s'\n", nr, current_name);
691691
if (OPT_repair) {
692692
if (ask("Mark as 'in use'", 1))

Diff for: util-linux/ipcs.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ static NOINLINE void do_shm(void)
166166
case STATUS:
167167
printf("------ Shared Memory %s --------\n", "Status");
168168
printf("segments allocated %d\n"
169-
"pages allocated %ld\n"
170-
"pages resident %ld\n"
171-
"pages swapped %ld\n"
172-
"Swap performance: %ld attempts\t%ld successes\n",
169+
"pages allocated %lu\n"
170+
"pages resident %lu\n"
171+
"pages swapped %lu\n"
172+
"Swap performance: %lu attempts\t%lu successes\n",
173173
shm_info.used_ids,
174174
shm_info.shm_tot,
175175
shm_info.shm_rss,
@@ -569,7 +569,7 @@ static void print_sem(int semid)
569569
if (val < 0 || ncnt < 0 || zcnt < 0 || pid < 0) {
570570
bb_perror_msg_and_die("semctl");
571571
}
572-
printf("%-10d %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
572+
printf("%-10u %-10d %-10d %-10d %-10d\n", i, val, ncnt, zcnt, pid);
573573
}
574574
bb_putchar('\n');
575575
}

Diff for: util-linux/mkfs_minix.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ static void get_list_blocks(char *filename)
505505

506506
listfile = xfopen_for_read(filename);
507507
while (!feof(listfile)) {
508-
fscanf(listfile, "%ld\n", &blockno);
508+
fscanf(listfile, "%lu\n", &blockno);
509509
mark_zone(blockno);
510510
G.badblocks++;
511511
}

Diff for: util-linux/readprofile.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
152152

153153
step = buf[0];
154154
if (optInfo) {
155-
printf("Sampling_step: %i\n", step);
155+
printf("Sampling_step: %u\n", step);
156156
return EXIT_SUCCESS;
157157
}
158158

@@ -219,10 +219,10 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
219219
&& (fn_len = next_add-fn_add) != 0
220220
) {
221221
if (optVerbose)
222-
printf("%016llx %-40s %6i %8.4f\n", fn_add,
222+
printf("%016llx %-40s %6u %8.4f\n", fn_add,
223223
fn_name, this, this/(double)fn_len);
224224
else
225-
printf("%6i %-40s %8.4f\n",
225+
printf("%6u %-40s %8.4f\n",
226226
this, fn_name, this/(double)fn_len);
227227
if (optSub) {
228228
unsigned long long scan;
@@ -246,14 +246,14 @@ int readprofile_main(int argc UNUSED_PARAM, char **argv)
246246
}
247247

248248
/* clock ticks, out of kernel text - probably modules */
249-
printf("%6i %s\n", buf[len/sizeof(*buf)-1], "*unknown*");
249+
printf("%6u %s\n", buf[len/sizeof(*buf)-1], "*unknown*");
250250

251251
/* trailer */
252252
if (optVerbose)
253-
printf("%016x %-40s %6i %8.4f\n",
253+
printf("%016x %-40s %6u %8.4f\n",
254254
0, "total", total, total/(double)(fn_add-add0));
255255
else
256-
printf("%6i %-40s %8.4f\n",
256+
printf("%6u %-40s %8.4f\n",
257257
total, "total", total/(double)(fn_add-add0));
258258

259259
fclose(map);

0 commit comments

Comments
 (0)