Skip to content

Commit e18f268

Browse files
committed
Fixed output.c
Handle non 0 terminated strings
1 parent bb695a7 commit e18f268

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

output.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <string.h>
66
#include <stdarg.h>
77

8+
#define STRING_MAX 4096
9+
810
output_t output = { .level = verbose };
911

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

3032
PREFIX(STDOUT_FILENO, l);
31-
write(STDOUT_FILENO, str, strlen(str));
33+
write(STDOUT_FILENO, str, strnlen(str, STRING_MAX));
3234
}
3335

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

3840
PREFIX(STDERR_FILENO, l);
39-
write(STDERR_FILENO, str, strlen(str));
41+
write(STDERR_FILENO, str, strnlen(str, STRING_MAX));
4042
}
4143

4244
void sprintln(char *str, output_level_t l)

0 commit comments

Comments
 (0)