Skip to content

Commit

Permalink
Fix incorrect printf format specifier
Browse files Browse the repository at this point in the history
PRI macros should be used for uintptr_t. Calling a printf-like function
with the wrong type of arguments causes unpredictable behavior.
  • Loading branch information
szsam committed Mar 27, 2024
1 parent d8cc0b0 commit 8f7c623
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/PikaObj.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

#include "PikaObj.h"
#include <stdint.h>
#include <inttypes.h>
#include "BaseObj.h"
#include "PikaCompiler.h"
#include "PikaParser.h"
Expand Down Expand Up @@ -2795,7 +2796,7 @@ void pika_eventListener_registEventCallback(PikaEventListener* listener,
Arg* eventCallback) {
pika_assert(NULL != listener);
char hash_str[32] = {0};
pika_sprintf(hash_str, "C%d", eventId);
pika_sprintf(hash_str, "C%" PRIuPTR, eventId);
obj_newDirectObj(listener, hash_str, New_TinyObj);
PikaObj* oHandle = obj_getPtr(listener, hash_str);
obj_setEventCallback(oHandle, eventId, eventCallback, listener);
Expand Down Expand Up @@ -2919,7 +2920,7 @@ Arg* __eventListener_runEvent(PikaEventListener* listener,
pika_debug("event handler: %p", handler);
if (NULL == handler) {
pika_platform_printf(
"Error: can not find event handler by id: [0x%02x]\r\n", eventId);
"Error: can not find event handler by id: [0x%02" PRIxPTR "]\r\n", eventId);
return NULL;
}
Arg* eventCallBack = obj_getArg(handler, "eventCallBack");
Expand Down

0 comments on commit 8f7c623

Please sign in to comment.