{"action":"opened","issue":{"url":"https://api.github.com/repos/vibraphone/cjson-bson/issues/4","labels_url":"https://api.github.com/repos/vibraphone/cjson-bson/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/vibraphone/cjson-bson/issues/4/comments","events_url":"https://api.github.com/repos/vibraphone/cjson-bson/issues/4/events","html_url":"https://github.com/vibraphone/cjson-bson/issues/4","id":83981700,"number":4,"title":"printf warning about wrong format","user":{"login":"UnePierre","id":398986,"avatar_url":"https://avatars.githubusercontent.com/u/398986?v=3","gravatar_id":"","url":"https://api.github.com/users/UnePierre","html_url":"https://github.com/UnePierre","followers_url":"https://api.github.com/users/UnePierre/followers","following_url":"https://api.github.com/users/UnePierre/following{/other_user}","gists_url":"https://api.github.com/users/UnePierre/gists{/gist_id}","starred_url":"https://api.github.com/users/UnePierre/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/UnePierre/subscriptions","organizations_url":"https://api.github.com/users/UnePierre/orgs","repos_url":"https://api.github.com/users/UnePierre/repos","events_url":"https://api.github.com/users/UnePierre/events{/privacy}","received_events_url":"https://api.github.com/users/UnePierre/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-02T11:34:39Z","updated_at":"2015-06-02T11:34:39Z","closed_at":null,"body":"Hi!  Nice implementation.\r\n\r\n# Problem\r\n\r\nMy build issues a warning about a mismatch in printf()-Arguments:\r\n\r\n```\r\ncJSON_BSON.c:393:5: warning: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘ptrdiff_t’ [-Wformat=]\r\n```\r\n\r\n# Fix 1\r\nThat can be remedied by an explicit cast, as shown by the following patch:\r\n\r\n```\r\ndiff --git a/cJSON_BSON.c b/cJSON_BSON.c\r\nindex d92ab40..352dabb 100644\r\n--- a/cJSON_BSON.c\r\n+++ b/cJSON_BSON.c\r\n@@ -390,7 +390,7 @@ size_t bson_item_name(cJSON* item, char* buf, size_t bufsize, ptrdiff_t* idxName\r\n   size_t result = 0;\r\n   if (idxName)\r\n     {\r\n-    result = snprintf(buf, bufsize, \"%lu\", *idxName);\r\n+    result = snprintf(buf, bufsize, \"%lu\", (long unsigned)(*idxName));\r\n     if (result > bufsize)\r\n       result = bufsize - 1; /* Prevent overruns */\r\n     (*idxName) ++; /* increment the index for the next item. */\r\n```\r\n\r\n# Fix 2\r\nMy preferred solution would be to ```#include <inttypes.h>``` and use ```\"%\" PRIuPTR``` instead of ```\"%lu\"```.\r\n\r\n```\r\n--- a/cJSON_BSON.c\r\n+++ b/cJSON_BSON.c\r\n@@ -30,6 +30,7 @@\r\n #include <stdlib.h>\r\n #include <float.h>\r\n #include <limits.h>\r\n+#include <inttypes.h>\r\n #include <ctype.h>\r\n #include \"cJSON.h\"\r\n #include \"cJSON_BSON.h\"\r\n@@ -390,7 +391,7 @@ size_t bson_item_name(cJSON* item, char* buf, size_t bufsize, ptrdiff_t* idxName\r\n   size_t result = 0;\r\n   if (idxName)\r\n     {\r\n-    result = snprintf(buf, bufsize, \"%lu\", *idxName);\r\n+    result = snprintf(buf, bufsize, \"%\" PRIuPTR, *idxName);\r\n     if (result > bufsize)\r\n       result = bufsize - 1; /* Prevent overruns */\r\n     (*idxName) ++; /* increment the index for the next item. */\r\n```\r\n\r\nThanks,\r\nMax"}}