Skip to content

Commit 9b64c3e

Browse files
committed
Fix printf format issues in apps/json_parse, and actually call the usage() function.
1 parent ee90110 commit 9b64c3e

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

apps/json_parse.c

+7-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static const char *fname = NULL;
3131
#define json_tokener_get_parse_end(tok) ((tok)->char_offset)
3232
#endif
3333

34-
static void usage(int exitval, const char *errmsg);
34+
static void usage(const char *argv0, int exitval, const char *errmsg);
3535
static void showmem(void);
3636
static int parseit(int fd, int (*callback)(struct json_object *));
3737
static int showobj(struct json_object *new_obj);
@@ -42,7 +42,7 @@ static void showmem(void)
4242
struct rusage rusage;
4343
memset(&rusage, 0, sizeof(rusage));
4444
getrusage(RUSAGE_SELF, &rusage);
45-
printf("maxrss: %d KB\n", rusage.ru_maxrss);
45+
printf("maxrss: %ld KB\n", rusage.ru_maxrss);
4646
#endif
4747
}
4848

@@ -137,14 +137,14 @@ static int showobj(struct json_object *new_obj)
137137
return 0;
138138
}
139139

140-
static void usage(int exitval, const char *errmsg)
140+
static void usage(const char *argv0, int exitval, const char *errmsg)
141141
{
142142
FILE *fp = stdout;
143143
if (exitval != 0)
144144
fp = stderr;
145145
if (errmsg != NULL)
146146
fprintf(fp, "ERROR: %s\n\n", errmsg);
147-
fprintf(fp, "Usage: %s [-f] [-n] [-s]\n");
147+
fprintf(fp, "Usage: %s [-f] [-n] [-s]\n", argv0);
148148
fprintf(fp, " -f - Format the output with JSON_C_TO_STRING_PRETTY\n");
149149
fprintf(fp, " -n - No output\n");
150150
fprintf(fp, " -s - Parse in strict mode, flags:\n");
@@ -160,14 +160,15 @@ int main(int argc, char **argv)
160160
json_object *new_obj;
161161
int opt;
162162

163-
while ((opt = getopt(argc, argv, "fns")) != -1)
163+
while ((opt = getopt(argc, argv, "fhns")) != -1)
164164
{
165165
switch (opt)
166166
{
167167
case 'f': formatted_output = 1; break;
168168
case 'n': show_output = 0; break;
169169
case 's': strict_mode = 1; break;
170-
default: /* '?' */ fprintf(stderr, "Usage: %s [-f]\n", argv[0]); exit(EXIT_FAILURE);
170+
case 'h': usage(argv[0], 0, NULL);
171+
default: /* '?' */ usage(argv[0], 1, "Unknown arguments");
171172
}
172173
}
173174

0 commit comments

Comments
 (0)