From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: Eric Sunshine <sunshine@sunshineco.com>,
Junio C Hamano <gitster@pobox.com>,
Stefan Beller <stefanbeller@googlemail.com>
Subject: [PATCH v2 8/9] mailmap: debug: avoid passing NULL to fprintf() '%s' directive
Date: Mon, 15 Jul 2013 02:54:12 -0400 [thread overview]
Message-ID: <1373871253-96480-9-git-send-email-sunshine@sunshineco.com> (raw)
In-Reply-To: <1373871253-96480-1-git-send-email-sunshine@sunshineco.com>
POSIX does not state the behavior of format directive '%s' 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>
---
mailmap.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/mailmap.c b/mailmap.c
index 4cc6e81..928e6e5 100644
--- a/mailmap.c
+++ b/mailmap.c
@@ -5,8 +5,10 @@
#define DEBUG_MAILMAP 0
#if DEBUG_MAILMAP
#define debug_mm(...) fprintf(stderr, __VA_ARGS__)
+#define debug_str(X) ((X) ? (X) : "(none)")
#else
static inline void debug_mm(const char *format, ...) {}
+static inline const char *debug_str(const char *s) { return s; }
#endif
const char *git_mailmap_file;
@@ -29,7 +31,7 @@ struct mailmap_entry {
static void free_mailmap_info(void *p, const char *s)
{
struct mailmap_info *mi = (struct mailmap_info *)p;
- debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, mi->name, mi->email);
+ debug_mm("mailmap: -- complex: '%s' -> '%s' <%s>\n", s, debug_str(mi->name), debug_str(mi->email));
free(mi->name);
free(mi->email);
}
@@ -38,7 +40,8 @@ static void free_mailmap_entry(void *p, const char *s)
{
struct mailmap_entry *me = (struct mailmap_entry *)p;
debug_mm("mailmap: removing entries for <%s>, with %d sub-entries\n", s, me->namemap.nr);
- debug_mm("mailmap: - simple: '%s' <%s>\n", me->name, me->email);
+ debug_mm("mailmap: - simple: '%s' <%s>\n", debug_str(me->name), debug_str(me->email));
+
free(me->name);
free(me->email);
@@ -94,7 +97,7 @@ static void add_mapping(struct string_list *map,
}
debug_mm("mailmap: '%s' <%s> -> '%s' <%s>\n",
- old_name, old_email, new_name, new_email);
+ debug_str(old_name), old_email, debug_str(new_name), debug_str(new_email));
}
static char *parse_name_and_email(char *buffer, char **name,
@@ -309,7 +312,7 @@ int map_user(struct string_list *map,
struct mailmap_entry *me;
debug_mm("map_user: map '%.*s' <%.*s>\n",
- (int)*namelen, *name, (int)*emaillen, *email);
+ (int)*namelen, debug_str(*name), (int)*emaillen, debug_str(*email));
item = lookup_prefix(map, *email, *emaillen);
if (item != NULL) {
@@ -337,8 +340,8 @@ int map_user(struct string_list *map,
*name = mi->name;
*namelen = strlen(*name);
}
- debug_mm("map_user: to '%.*s' <%.*s>\n", (int)*namelen, *name,
- (int)*emaillen, *email);
+ debug_mm("map_user: to '%.*s' <%.*s>\n", (int)*namelen, debug_str(*name),
+ (int)*emaillen, debug_str(*email));
return 1;
}
debug_mm("map_user: --\n");
--
1.8.3.2.804.g0da7a53
next prev parent reply other threads:[~2013-07-15 6:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-15 6:54 [PATCH v2 0/9] mailmap fixes Eric Sunshine
2013-07-15 6:54 ` [PATCH v2 1/9] t4203: demonstrate loss of single-character name in mailmap entry Eric Sunshine
2013-07-15 6:54 ` [PATCH v2 2/9] mailmap: do not lose single-letter names Eric Sunshine
2013-07-15 6:54 ` [PATCH v2 3/9] t4203: demonstrate loss of uppercase characters in canonical email Eric Sunshine
2013-07-15 6:54 ` [PATCH v2 4/9] mailmap: do not downcase mailmap entries Eric Sunshine
2013-07-15 6:54 ` [PATCH v2 5/9] mailmap: debug: fix out-of-order fprintf() arguments Eric Sunshine
2013-07-15 15:18 ` Junio C Hamano
2013-07-15 6:54 ` [PATCH v2 6/9] mailmap: debug: fix malformed fprintf() format directive Eric Sunshine
2013-07-15 6:54 ` [PATCH v2 7/9] mailmap: debug: eliminate -Wformat field precision type warning Eric Sunshine
2013-07-15 6:54 ` Eric Sunshine [this message]
2013-07-15 6:54 ` [PATCH v2 9/9] mailmap: style fixes Eric Sunshine
2013-07-15 15:22 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1373871253-96480-9-git-send-email-sunshine@sunshineco.com \
--to=sunshine@sunshineco.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=stefanbeller@googlemail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).