summaryrefslogtreecommitdiffstats
path: root/native_client_sdk
diff options
context:
space:
mode:
authorbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-17 17:31:03 +0000
committerbinji@chromium.org <binji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-17 17:31:03 +0000
commitdd267c664660804fce1e49c062d5e875d3f82c75 (patch)
treea494120636c3c0a240645de92e5c2cbe1231b0c7 /native_client_sdk
parenta2f705fe1382a3661bc3438c7b5ec0373e03afec (diff)
downloadchromium_src-dd267c664660804fce1e49c062d5e875d3f82c75.zip
chromium_src-dd267c664660804fce1e49c062d5e875d3f82c75.tar.gz
chromium_src-dd267c664660804fce1e49c062d5e875d3f82c75.tar.bz2
[NaCl SDK] Fix broken printf format strings in the nacl_io_demo.
We use custom printf functions for nacl_io_demo, which were not being checked for passing the correct arguments. This CL adds a printf format checking attribute to those functions, as well as dbgprintf in nacl_io. BUG=363096 R=sbc@chromium.org Review URL: https://codereview.chromium.org/239543014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264562 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'native_client_sdk')
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/handlers.c10
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c2
-rw-r--r--native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h7
-rw-r--r--native_client_sdk/src/libraries/nacl_io/dbgprint.h2
-rw-r--r--native_client_sdk/src/libraries/sdk_util/macros.h16
5 files changed, 27 insertions, 10 deletions
diff --git a/native_client_sdk/src/examples/demo/nacl_io/handlers.c b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
index d615eda..ae40d2d 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/handlers.c
+++ b/native_client_sdk/src/examples/demo/nacl_io/handlers.c
@@ -379,11 +379,11 @@ int HandleFseek(int num_params, char** params, char** output) {
offset = ftell(file);
if (offset < 0) {
*output = PrintfToNewString(
- "fseek succeeded, but ftell returned error %d.", offset);
+ "fseek succeeded, but ftell returned error %ld.", offset);
return 4;
}
- *output = PrintfToNewString("fseek\1%s\1%d", file_index_string, offset);
+ *output = PrintfToNewString("fseek\1%s\1%ld", file_index_string, offset);
return 0;
}
@@ -507,7 +507,7 @@ int HandleStat(int num_params, char** params, char** output) {
return 2;
}
- *output = PrintfToNewString("stat\1%s\1%d", filename, buf.st_size);
+ *output = PrintfToNewString("stat\1%s\1%lld", filename, buf.st_size);
return 0;
}
@@ -601,8 +601,8 @@ int HandleReaddir(int num_params, char** params, char** output) {
entry = readdir(dir);
if (entry != NULL) {
- *output = PrintfToNewString("readdir\1%s\1%d\1%s", dir_index_string,
- entry->d_ino, entry->d_name);
+ *output = PrintfToNewString(
+ "readdir\1%s\1%lld\1%s", dir_index_string, entry->d_ino, entry->d_name);
} else {
*output = PrintfToNewString("readdir\1%s\1\1", dir_index_string);
}
diff --git a/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c
index 76eea39..66b2591 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c
+++ b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.c
@@ -349,7 +349,7 @@ static void Messaging_HandleMessage(PP_Instance instance,
if (!EnqueueMessage(strdup(buffer))) {
struct PP_Var var;
var = PrintfToVar(
- "Warning: dropped message \"%s\" because the queue was full.", message);
+ "Warning: dropped message \"%s\" because the queue was full.", buffer);
ppb_messaging_interface->PostMessage(g_instance, var);
}
}
diff --git a/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h
index 6eccb5e..b507110 100644
--- a/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h
+++ b/native_client_sdk/src/examples/demo/nacl_io/nacl_io_demo.h
@@ -7,11 +7,12 @@
#include <stdarg.h>
#include "ppapi/c/pp_var.h"
+#include "sdk_util/macros.h" // for PRINTF_LIKE
struct PP_Var CStrToVar(const char* str);
-char* VprintfToNewString(const char* format, va_list args);
-char* PrintfToNewString(const char* format, ...);
-struct PP_Var PrintfToVar(const char* format, ...);
+char* VprintfToNewString(const char* format, va_list args) PRINTF_LIKE(1, 0);
+char* PrintfToNewString(const char* format, ...) PRINTF_LIKE(1, 2);
+struct PP_Var PrintfToVar(const char* format, ...) PRINTF_LIKE(1, 2);
uint32_t VarToCStr(struct PP_Var var, char* buffer, uint32_t length);
#endif /* NACL_IO_DEMO_H_ */
diff --git a/native_client_sdk/src/libraries/nacl_io/dbgprint.h b/native_client_sdk/src/libraries/nacl_io/dbgprint.h
index 305fea5..91fcf58 100644
--- a/native_client_sdk/src/libraries/nacl_io/dbgprint.h
+++ b/native_client_sdk/src/libraries/nacl_io/dbgprint.h
@@ -9,7 +9,7 @@
EXTERN_C_BEGIN
-void dbgprintf(const char* format, ...);
+void dbgprintf(const char* format, ...) PRINTF_LIKE(1, 2);
EXTERN_C_END
diff --git a/native_client_sdk/src/libraries/sdk_util/macros.h b/native_client_sdk/src/libraries/sdk_util/macros.h
index e2e5400..b1bc75e 100644
--- a/native_client_sdk/src/libraries/sdk_util/macros.h
+++ b/native_client_sdk/src/libraries/sdk_util/macros.h
@@ -46,4 +46,20 @@
force_link_##x = 1; \
}
+/**
+ * Macro to error out when a printf-like function is passed incorrect arguments.
+ *
+ * Use like this:
+ * void foo(const char* fmt, ...) PRINTF_LIKE(1, 2);
+ *
+ * The first argument is the location of the fmt string (1-based).
+ * The second argument is the location of the first argument to validate (also
+ * 1-based, but can be zero if the function uses a va_list, like vprintf.)
+ */
+#if defined(__GNUC__)
+#define PRINTF_LIKE(a, b) __attribute__ ((format(printf, a, b)))
+#else
+#define PRINTF_LIKE(a, b)
+#endif
+
#endif /* LIBRARIES_SDK_UTIL_MACROS_H_ */