aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2003-12-17 12:26:38 +0000
committerWerner Koch <[email protected]>2003-12-17 12:26:38 +0000
commit8ab35a7d26707dfa0032b3b0dbde6a984a9683cb (patch)
tree6506bd41badddfc72100a5f6c37a51c7f2099560
parent(initialize): Replaced use of non-literal forma (diff)
downloadgnupg-8ab35a7d26707dfa0032b3b0dbde6a984a9683cb.tar.gz
gnupg-8ab35a7d26707dfa0032b3b0dbde6a984a9683cb.zip
* gettime.c (asctimestamp): Add a note on a non-avoidable gcc warning.
* util.h [!HAVE_VASPRINTF]: Add printf format attribute to the replacement function. * miscellaneous.c (xasprintf): New.
-rw-r--r--common/ChangeLog9
-rw-r--r--common/gettime.c6
-rw-r--r--common/miscellaneous.c20
-rw-r--r--common/util.h8
4 files changed, 40 insertions, 3 deletions
diff --git a/common/ChangeLog b/common/ChangeLog
index 2344868a7..e69df733f 100644
--- a/common/ChangeLog
+++ b/common/ChangeLog
@@ -1,3 +1,12 @@
+2003-12-17 Werner Koch <[email protected]>
+
+ * gettime.c (asctimestamp): Add a note on a non-avoidable gcc warning.
+
+ * util.h [!HAVE_VASPRINTF]: Add printf format attribute to the
+ replacement function.
+
+ * miscellaneous.c (xasprintf): New.
+
2003-11-14 Werner Koch <[email protected]>
* mkdtemp.c (mkdtemp): Use gcry_create_nonce.
diff --git a/common/gettime.c b/common/gettime.c
index ed1d0c819..93e4ba113 100644
--- a/common/gettime.c
+++ b/common/gettime.c
@@ -246,9 +246,11 @@ asctimestamp( u32 stamp )
mem2str( fmt, nl_langinfo(D_T_FMT), DIM(fmt)-3 );
if( strstr( fmt, "%Z" ) == NULL )
strcat( fmt, " %Z");
- strftime( buffer, DIM(buffer)-1, fmt, tp );
+ /* NOTE: gcc -Wformat-noliteral will complain here. I have
+ found no way to suppress this warning .*/
+ strftime (buffer, DIM(buffer)-1, fmt, tp);
#else
- /* fixme: we should check whether the locale appends a " %Z"
+ /* FIXME: we should check whether the locale appends a " %Z"
* These locales from glibc don't put the " %Z":
* fi_FI hr_HR ja_JP lt_LT lv_LV POSIX ru_RU ru_SU sv_FI sv_SE zh_CN
*/
diff --git a/common/miscellaneous.c b/common/miscellaneous.c
index bdb12c574..4937bd7ce 100644
--- a/common/miscellaneous.c
+++ b/common/miscellaneous.c
@@ -25,6 +25,26 @@
#include "util.h"
#include "iobuf.h"
+/* Same as asprintf but return an allocated buffer suitable to be
+ freed using xfree. This function simply dies on memory failure,
+ thus no extra check is required. */
+char *
+xasprintf (const char *fmt, ...)
+{
+ va_list ap;
+ char *buf, *p;
+
+ va_start (ap, fmt);
+ if (vasprintf (&buf, fmt, ap) < 0)
+ log_fatal ("asprintf failed: %s\n", strerror (errno));
+ va_end (ap);
+ p = xstrdup (buf);
+ free (buf);
+ return p;
+}
+
+
+
/* Decide whether the filename is stdout or a real filename and return
* an appropriate string. */
const char *
diff --git a/common/util.h b/common/util.h
index e38ced337..80a1d01a6 100644
--- a/common/util.h
+++ b/common/util.h
@@ -99,6 +99,12 @@ int answer_is_yes_no_quit (const char *s);
/*-- miscellaneous.c --*/
+
+/* Same as asprintf but return an allocated buffer suitable to be
+ freed using xfree. This function simply dies on memory failure,
+ thus no extra check is required. */
+char *xasprintf (const char *fmt, ...) JNLIB_GCC_A_PRINTF(1,2);
+
const char *print_fname_stdout (const char *s);
const char *print_fname_stdin (const char *s);
void print_string (FILE *fp, const byte *p, size_t n, int delim);
@@ -113,7 +119,7 @@ int is_file_compressed (const char *s, int *ret_rc);
#if !HAVE_VASPRINTF
#include <stdarg.h>
int vasprintf (char **result, const char *format, va_list args);
-int asprintf (char **result, const char *format, ...);
+int asprintf (char **result, const char *format, ...) JNLIB_GCC_A_PRINTF(2,3);
#endif