Skip to content

Commit

Permalink
Merge pull request #50 from xaizek/fix-null-char-in-printf
Browse files Browse the repository at this point in the history
Fix line truncation on printing null character via *printf() functions
  • Loading branch information
cehoffman authored Jul 20, 2017
2 parents cb9c3fd + b25866e commit 399e3b1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/stderred.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ int FUNC(fputs_unlocked)(const char *str, FILE *stream) {
int FUNC(vfprintf)(FILE *stream, const char *format, va_list ap) {
char *buf = NULL;

if (vasprintf(&buf, format, ap) > 0) {
int result = FUNC(fwrite)(buf, sizeof(char), strlen(buf)/sizeof(char), stream);
int nprinted = vasprintf(&buf, format, ap);
if (nprinted > 0) {
int result = FUNC(fwrite)(buf, sizeof(char), nprinted, stream);
free(buf);
return result;
} else {
Expand Down Expand Up @@ -210,8 +211,9 @@ int FUNC(fprintf_unlocked)(FILE *stream, const char *format, ...) {
char *buf = NULL;
int result = -1;

if ( vasprintf(&buf, format, args) > 0) {
result = FUNC(fwrite_unlocked)(buf, sizeof(char), strlen(buf)/sizeof(char), stream);
int nprinted = vasprintf(&buf, format, args);
if (nprinted > 0) {
result = FUNC(fwrite_unlocked)(buf, sizeof(char), nprinted, stream);
free(buf);
}

Expand Down

0 comments on commit 399e3b1

Please sign in to comment.