Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int set_socket_rcvbuf(int fd, int size) {
*
* @param level Message log level
* @param format printf style format string
* @returns Whatever printf returns
* @return Message length (newline included)
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The updated docstring claims this function returns the message length (newline included), but the implementation still returns fputs()'s status code (and potentially modified by later logic). Either adjust the implementation to return the actual number of characters written (based on the rendered message and whether a newline was appended), or keep the original semantics and document it as a fputs()-style return (non-negative on success, EOF on error).

Suggested change
* @return Message length (newline included)
* @return Non-negative on success, EOF on output error

Copilot uses AI. Check for mistakes.
*/
int logger(loglevel_t level, const char *format, ...) {
va_list ap;
Expand Down Expand Up @@ -120,7 +120,10 @@ int logger(loglevel_t level, const char *format, ...) {
// Automatically add newline if format doesn't end with one
if (format && strlen(format) > 0 && format[strlen(format) - 1] != '\n') {
fputc('\n', stdout);
r++;
Comment on lines 122 to +123
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r++ here assumes r is a character count, but r is currently the return value from fputs() (a non-negative/EOF status). Incrementing it can also mask an EOF from fputs() (e.g., -1 becomes 0), changing error signaling. Suggestion: remove the r++ unless you change r to track bytes written, and if you do, ensure errors from fputs()/fputc() aren’t lost.

Suggested change
fputc('\n', stdout);
r++;
if (fputc('\n', stdout) == EOF) {
r = EOF;
}

Copilot uses AI. Check for mistakes.
}

fflush(stdout);
}
return r;
}
Expand Down
Loading