mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Khem Raj <raj.khem@gmail.com>
To: musl@lists.openwall.com
Cc: Khem Raj <raj.khem@gmail.com>
Subject: [PATCH] libintl.h: Add format argument attributes to gettext function prototypes
Date: Sun, 13 Sep 2015 06:29:04 +0000	[thread overview]
Message-ID: <1442125744-27934-1-git-send-email-raj.khem@gmail.com> (raw)

compiling glib-2.0 clang errors out with

error: format string is not a string literal

when these functions are used, it can be enforced that the format
arguments to these gettext* functions  be string literals, so that the compiler knows that it
always will be string literals

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 include/libintl.h | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/include/libintl.h b/include/libintl.h
index a2dada6..6a707bf 100644
--- a/include/libintl.h
+++ b/include/libintl.h
@@ -8,16 +8,24 @@ extern "C" {
 #define __USE_GNU_GETTEXT 1
 #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 1 : -1)
 
-char *gettext(const char *);
-char *dgettext(const char *, const char *);
-char *dcgettext(const char *, const char *, int);
-char *ngettext(const char *, const char *, unsigned long);
-char *dngettext(const char *, const char *, const char *, unsigned long);
-char *dcngettext(const char *, const char *, const char *, unsigned long, int);
+#if __GNUC__ >= 3
+#define __fa(n) __attribute__ ((__format_arg__ (n)))
+#else
+#define __fa(n)
+#endif
+
+char *gettext(const char *) __fa(1);
+char *dgettext(const char *, const char *) __fa(2);
+char *dcgettext(const char *, const char *, int) __fa(2);
+char *ngettext(const char *, const char *, unsigned long) __fa(1) __fa(2);
+char *dngettext(const char *, const char *, const char *, unsigned long) __fa(2) __fa(3);
+char *dcngettext(const char *, const char *, const char *, unsigned long, int) __fa(2) __fa(3);
 char *textdomain(const char *);
 char *bindtextdomain (const char *, const char *);
 char *bind_textdomain_codeset(const char *, const char *);
 
+#undef __fa
+
 #ifdef __cplusplus
 }
 #endif
-- 
2.5.2



             reply	other threads:[~2015-09-13  6:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-13  6:29 Khem Raj [this message]
2015-09-15 20:35 ` Rich Felker

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442125744-27934-1-git-send-email-raj.khem@gmail.com \
    --to=raj.khem@gmail.com \
    --cc=musl@lists.openwall.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://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).