-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The only hardening being done here is to set the char** parameter to thos functions to NULL in case of an error, to prevent it from being used should people forget to check return values. This is already done on some BSD, as well as in Rocky Linux.
- Loading branch information
Showing
5 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#define _GNU_SOURCE | ||
#include "common.h" | ||
|
||
#include <assert.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
int main(int argc, char** argv) { | ||
char* buf; | ||
asprintf(&buf, "total: %d+%d=%d", 1, 2, 3); | ||
puts(buf); | ||
free(buf); | ||
|
||
#ifndef __clang__ | ||
asprintf(&buf, "total: %", 1); | ||
assert(buf == NULL); | ||
#endif | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#define _GNU_SOURCE | ||
#include "common.h" | ||
|
||
#include <assert.h> | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
void test(const char *fmt, ...) | ||
{ | ||
char* buf; | ||
va_list args; | ||
va_start(args, fmt); | ||
vasprintf(&buf, fmt, args); | ||
va_end(args); | ||
puts(buf); | ||
free(buf); | ||
} | ||
|
||
void test2(const char *fmt, ...) | ||
{ | ||
char* buf; | ||
va_list args; | ||
va_start(args, fmt); | ||
vasprintf(&buf, fmt, args); | ||
va_end(args); | ||
assert(buf == NULL); | ||
} | ||
|
||
int main(int argc, char** argv) { | ||
test("Total: %d+%d=%d", 1, 2, 3); | ||
#ifndef __clang__ | ||
test2("Total: %", 1, 2, 3); | ||
#endif | ||
return 0; | ||
} |