blob: 94794a5f9265c7b94248a4a465874e99397c2f75 [file] [log] [blame]
Brad Bishop23eaf032019-11-20 05:15:02 -05001From ef170dda7fbab53682c9bc287dec93fa86130bc9 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sun, 9 Sep 2018 21:49:59 -0700
4Subject: [PATCH] add a formatting attribute check
5
6Tell Clang that parameter is a printf style format using the
7attribute flag
8
9This helps in avoiding below warnings seen with clang
10
11unarr.c:106:22: error: format string is not a string literal
12[-Werror,-Wformat-nonliteral]
13| vfprintf(stderr, msg, args);
14| ^~~
15
16Upstream-Status: Pending
17Signed-off-by: Khem Raj <raj.khem@gmail.com>
18---
19 cut-n-paste/unarr/common/unarr.c | 2 +-
20 1 file changed, 1 insertion(+), 1 deletion(-)
21
Brad Bishop23eaf032019-11-20 05:15:02 -050022--- a/cut-n-paste/synctex/synctex_parser_utils.c
23+++ b/cut-n-paste/synctex/synctex_parser_utils.c
24@@ -87,11 +87,11 @@ void _synctex_free(void * ptr) {
25 # include <syslog.h>
26 #endif
27
28-int _synctex_error(const char * reason, ...) __attribute__((__format__ (__printf__, 1, 2)));
29-int _synctex_log(int level, const char * prompt, const char * reason, va_list arg) __attribute__((__format__ (__printf__, 3, 0)));
30-
31-int _synctex_log(int level, const char * prompt, const char * reason,va_list arg) {
32+static int _synctex_log(int level, const char * prompt, const char * reason, ...) SYNCTEX_PRINTF_FORMAT(3, 0);
33+static int _synctex_log(int level, const char * prompt, const char * reason, ...) {
34+ va_list arg;
35 int result;
36+ va_start(arg, reason);
37 # ifdef SYNCTEX_RECENT_WINDOWS
38 {/* This code is contributed by William Blum.
39 As it does not work on some older computers,
40@@ -133,10 +133,10 @@ int _synctex_log(int level, const char *
41 result += vfprintf(where, reason, arg);
42 result += fprintf(where,"\n");
43 # endif
44+ va_end(arg);
45 return result;
46 }
47
48-__attribute__((__format__ (__printf__, 1, 0)))
49 int _synctex_error(const char * reason,...) {
50 va_list arg;
51 int result;
52@@ -355,6 +355,7 @@ char * _synctex_merge_strings(const char
53 size_t len = strlen(temp);
54 if(UINT_MAX-len<size) {
55 _synctex_error("! _synctex_merge_strings: Capacity exceeded.");
56+ va_end(arg);
57 return NULL;
58 }
59 size+=len;
60@@ -374,6 +375,7 @@ char * _synctex_merge_strings(const char
61 if(dest != strncpy(dest,temp,size)) {
62 _synctex_error("! _synctex_merge_strings: Copy problem");
63 free(result);
64+ va_end(arg);
65 result = NULL;
66 return NULL;
67 }
Brad Bishop23eaf032019-11-20 05:15:02 -050068--- a/cut-n-paste/synctex/synctex_parser_utils.h
69+++ b/cut-n-paste/synctex/synctex_parser_utils.h
70@@ -85,7 +85,11 @@ extern "C" {
71 # else
72 # define SYNCTEX_ARE_PATH_CHARACTERS_EQUAL(left,right) (toupper(left) != toupper(right))
73 # endif
74-
75+# ifdef __GNUC__
76+# define SYNCTEX_PRINTF_FORMAT(si, ftc) __attribute__ ((format (printf, si, ftc)))
77+# else
78+# define SYNCTEX_PRINTF_FORMAT(si, ftc)
79+# endif
80 /* This custom malloc functions initializes to 0 the newly allocated memory.
81 * There is no bzero function on windows. */
82 void *_synctex_malloc(size_t size);
83@@ -97,8 +101,8 @@ void _synctex_free(void * ptr);
84 /* This is used to log some informational message to the standard error stream.
85 * On Windows, the stderr stream is not exposed and another method is used.
86 * The return value is the number of characters printed. */
87- int _synctex_error(const char * reason,...);
88- int _synctex_debug(const char * reason,...);
89+ int _synctex_error(const char * reason,...) SYNCTEX_PRINTF_FORMAT(1, 2);
90+ int _synctex_debug(const char * reason,...) SYNCTEX_PRINTF_FORMAT(1, 2);
91
92 /* strip the last extension of the given string, this string is modified!
93 * This function depends on the OS because the path separator may differ.