Skip to content

Commit

Permalink
C99 has no _s funcs, right...
Browse files Browse the repository at this point in the history
  • Loading branch information
p0358 committed Nov 5, 2023
1 parent 33b44eb commit a8a5c59
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions examples/send-presence/send-presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ static void handleDebug(char isOut,
char* buf = (char*)malloc(len);
char* direction = isOut ? "send" : "receive";
if (!messageLength || !message || !message[0]) {
sprintf_s(buf, len, "[%s] [%s] <empty>", direction, opcodeName);
snprintf(buf, len, "[%s] [%s] <empty>", direction, opcodeName);
}
else {
int written = sprintf_s(buf, len, "[%s] [%s] ", direction, opcodeName);
strncpy_s(buf + written, len - written, message, messageLength);
int written = snprintf(buf, len, "[%s] [%s] ", direction, opcodeName);
int remaining = len - written;
int toWrite = remaining > (messageLength + 1) ? (messageLength + 1) : remaining;
int written2 = snprintf(buf + written, toWrite, message);
}
printf("[DEBUG] %s\n", buf);
free(buf);
Expand Down

0 comments on commit a8a5c59

Please sign in to comment.