mailmap: debug: avoid passing NULL to fprintf() '%s' conversion specification
POSIX does not state the behavior of '%s' conversion when passed a NULL pointer. Some implementations interpolate literal "(null)"; others may crash. Callers of debug_mm() often pass NULL as indication of either a missing name or email address. Instead, let's always supply a proper string pointer, and make it a bit more descriptive: "(none)" Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Eric Sunshine committed
Jul 15, 2013 at 02:54 UTC
fbfba7ade0dde36d8911973b1dac248b81ce1375
1 file changed
+9
-6
mailmap.c
+9
-6
@@ -5,8 +5,10 @@
5
#define DEBUG_MAILMAP 0
6
#if DEBUG_MAILMAP
7
#define debug_mm(...) fprintf(stderr, __VA_ARGS__)
8
+#define debug_str(X) ((X) ? (X) : "(none)")
9
#else
10
static inline void debug_mm(const char *format, ...) {}
11
+static inline const char *debug_str(const char *s) { return s; }
12
#endif
13
14
const char *git_mailmap_file;
@@ -29,7 +31,7 @@ struct mailmap_entry {
31
static void free_mailmap_info(void *p, const char *s)
32
{
33
struct mailmap_info *mi = (struct mailmap_info *)p;
32
- debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, mi->name, mi->email);
34
+ debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, debug_str(mi->name), debug_str(mi->email));
35
free(mi->name);
36
free(mi->email);
37
}
@@ -38,7 +40,8 @@ static void free_mailmap_entry(void *p, const char *s)
40
{
41
struct mailmap_entry *me = (struct mailmap_entry *)p;
42
debug_mm("mailmap: removing entries for <%s>, with %d sub-entries\n", s, me->namemap.nr);
41
- debug_mm("mailmap: - simple: '%s' <%s>\n", me->name, me->email);
43
+ debug_mm("mailmap: - simple: '%s' <%s>\n", debug_str(me->name), debug_str(me->email));
44
+
45
free(me->name);
46
free(me->email);
47
@@ -94,7 +97,7 @@ static void add_mapping(struct string_list *map,
97
}
98
99
debug_mm("mailmap: '%s' <%s> -> '%s' <%s>\n",
97
- old_name, old_email, new_name, new_email);
100
+ debug_str(old_name), old_email, debug_str(new_name), debug_str(new_email));
101
}
102
103
static char *parse_name_and_email(char *buffer, char **name,
@@ -309,7 +312,7 @@ int map_user(struct string_list *map,
312
struct mailmap_entry *me;
313
314
debug_mm("map_user: map '%.*s' <%.*s>\n",
312
- (int)*namelen, *name, (int)*emaillen, *email);
315
+ (int)*namelen, debug_str(*name), (int)*emaillen, debug_str(*email));
316
317
item = lookup_prefix(map, *email, *emaillen);
318
if (item != NULL) {
@@ -337,8 +340,8 @@ int map_user(struct string_list *map,
340
*name = mi->name;
341
*namelen = strlen(*name);
342
}
340
- debug_mm("map_user: to '%.*s' <%.*s>\n", (int)*namelen, *name,
341
- (int)*emaillen, *email);
343
+ debug_mm("map_user: to '%.*s' <%.*s>\n", (int)*namelen, debug_str(*name),
344
+ (int)*emaillen, debug_str(*email));
345
return 1;
346
}
347
debug_mm("map_user: --\n");