Skip to content

Commit

Permalink
Fixed output.c
Browse files Browse the repository at this point in the history
Handle non 0 terminated strings
  • Loading branch information
jroeger23 committed Mar 15, 2019
1 parent bb695a7 commit e18f268
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions output.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string.h>
#include <stdarg.h>

#define STRING_MAX 4096

output_t output = { .level = verbose };

#define PREFIX(FD, L) write(FD, prefixes[L], prefixes_len[L]);
Expand All @@ -28,15 +30,15 @@ void sprint(char *str, output_level_t l)
if(output.level < l) return;

PREFIX(STDOUT_FILENO, l);
write(STDOUT_FILENO, str, strlen(str));
write(STDOUT_FILENO, str, strnlen(str, STRING_MAX));
}

void eprint(char *str, output_level_t l)
{
if(output.level < l) return;

PREFIX(STDERR_FILENO, l);
write(STDERR_FILENO, str, strlen(str));
write(STDERR_FILENO, str, strnlen(str, STRING_MAX));
}

void sprintln(char *str, output_level_t l)
Expand Down

0 comments on commit e18f268

Please sign in to comment.