blob: c374fc943070ff8f1777e1a0d0cca88e420aff85 [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
22--- a/cut-n-paste/unarr/common/unarr.c
23+++ b/cut-n-paste/unarr/common/unarr.c
24@@ -92,7 +92,7 @@ size_t ar_get_global_comment(ar_archive
25 return ar->get_comment(ar, buffer, count);
26 }
27
28-void ar_log(const char *prefix, const char *file, int line, const char *msg, ...)
29+void __attribute__((__format__ (__printf__, 4, 5))) ar_log(const char *prefix, const char *file, int line, const char *msg, ...)
30 {
31 va_list args;
32 va_start(args, msg);
33--- a/cut-n-paste/synctex/synctex_parser_utils.c
34+++ b/cut-n-paste/synctex/synctex_parser_utils.c
35@@ -87,11 +87,11 @@ void _synctex_free(void * ptr) {
36 # include <syslog.h>
37 #endif
38
39-int _synctex_error(const char * reason, ...) __attribute__((__format__ (__printf__, 1, 2)));
40-int _synctex_log(int level, const char * prompt, const char * reason, va_list arg) __attribute__((__format__ (__printf__, 3, 0)));
41-
42-int _synctex_log(int level, const char * prompt, const char * reason,va_list arg) {
43+static int _synctex_log(int level, const char * prompt, const char * reason, ...) SYNCTEX_PRINTF_FORMAT(3, 0);
44+static int _synctex_log(int level, const char * prompt, const char * reason, ...) {
45+ va_list arg;
46 int result;
47+ va_start(arg, reason);
48 # ifdef SYNCTEX_RECENT_WINDOWS
49 {/* This code is contributed by William Blum.
50 As it does not work on some older computers,
51@@ -133,10 +133,10 @@ int _synctex_log(int level, const char *
52 result += vfprintf(where, reason, arg);
53 result += fprintf(where,"\n");
54 # endif
55+ va_end(arg);
56 return result;
57 }
58
59-__attribute__((__format__ (__printf__, 1, 0)))
60 int _synctex_error(const char * reason,...) {
61 va_list arg;
62 int result;
63@@ -355,6 +355,7 @@ char * _synctex_merge_strings(const char
64 size_t len = strlen(temp);
65 if(UINT_MAX-len<size) {
66 _synctex_error("! _synctex_merge_strings: Capacity exceeded.");
67+ va_end(arg);
68 return NULL;
69 }
70 size+=len;
71@@ -374,6 +375,7 @@ char * _synctex_merge_strings(const char
72 if(dest != strncpy(dest,temp,size)) {
73 _synctex_error("! _synctex_merge_strings: Copy problem");
74 free(result);
75+ va_end(arg);
76 result = NULL;
77 return NULL;
78 }
79--- a/cut-n-paste/synctex/synctex_parser.c
80+++ b/cut-n-paste/synctex/synctex_parser.c
81@@ -8411,6 +8411,7 @@ struct synctex_updater_t {
82 int length; /* the number of chars appended */
83 };
84
85+static int _synctex_updater_print(synctex_updater_p updater, const char * format, ...) SYNCTEX_PRINTF_FORMAT(2, 3);
86 static int _synctex_updater_print(synctex_updater_p updater, const char * format, ...) {
87 int result = 0;
88 if (updater) {
89@@ -8447,6 +8448,7 @@ static int vasprintf(char **ret,
90 /**
91 * gzvprintf is not available until OSX 10.10
92 */
93+static int _synctex_updater_print_gz(synctex_updater_p updater, const char * format, ...) SYNCTEX_PRINTF_FORMAT(2, 3);
94 static int _synctex_updater_print_gz(synctex_updater_p updater, const char * format, ...) {
95 int result = 0;
96 if (updater) {
97--- a/cut-n-paste/synctex/synctex_parser_utils.h
98+++ b/cut-n-paste/synctex/synctex_parser_utils.h
99@@ -85,7 +85,11 @@ extern "C" {
100 # else
101 # define SYNCTEX_ARE_PATH_CHARACTERS_EQUAL(left,right) (toupper(left) != toupper(right))
102 # endif
103-
104+# ifdef __GNUC__
105+# define SYNCTEX_PRINTF_FORMAT(si, ftc) __attribute__ ((format (printf, si, ftc)))
106+# else
107+# define SYNCTEX_PRINTF_FORMAT(si, ftc)
108+# endif
109 /* This custom malloc functions initializes to 0 the newly allocated memory.
110 * There is no bzero function on windows. */
111 void *_synctex_malloc(size_t size);
112@@ -97,8 +101,8 @@ void _synctex_free(void * ptr);
113 /* This is used to log some informational message to the standard error stream.
114 * On Windows, the stderr stream is not exposed and another method is used.
115 * The return value is the number of characters printed. */
116- int _synctex_error(const char * reason,...);
117- int _synctex_debug(const char * reason,...);
118+ int _synctex_error(const char * reason,...) SYNCTEX_PRINTF_FORMAT(1, 2);
119+ int _synctex_debug(const char * reason,...) SYNCTEX_PRINTF_FORMAT(1, 2);
120
121 /* strip the last extension of the given string, this string is modified!
122 * This function depends on the OS because the path separator may differ.