-
Notifications
You must be signed in to change notification settings - Fork 269
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8237 from tautschnig/features/asprintf
C library: model asprintf, test {v,}asprintf
- Loading branch information
Showing
5 changed files
with
67 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <assert.h> | ||
#include <stdio.h> | ||
|
||
int asprintf(char **ptr, const char *fmt, ...); | ||
|
||
int main() | ||
{ | ||
char *result = NULL; | ||
int bytes = asprintf(&result, "%d\n", 42); | ||
if(bytes != -1) | ||
{ | ||
assert(result[bytes] == 0); | ||
free(result); | ||
} | ||
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,8 @@ | ||
CORE | ||
main.c | ||
--pointer-check --bounds-check --unwind 10 --no-unwinding-assertions | ||
^EXIT=0$ | ||
^SIGNAL=0$ | ||
^VERIFICATION SUCCESSFUL$ | ||
-- | ||
^warning: ignoring |
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 |
---|---|---|
@@ -1,9 +1,26 @@ | ||
#include <assert.h> | ||
#include <stdarg.h> | ||
#include <stdio.h> | ||
|
||
int vasprintf(char **ptr, const char *fmt, va_list ap); | ||
|
||
int xasprintf(char **ptr, const char *format, ...) | ||
{ | ||
va_list list; | ||
va_start(list, format); | ||
int result = vasprintf(ptr, format, list); | ||
va_end(list); | ||
return result; | ||
} | ||
|
||
int main() | ||
{ | ||
vasprintf(); | ||
assert(0); | ||
char *result = NULL; | ||
int bytes = xasprintf(&result, "%d\n", 42); | ||
if(bytes != -1) | ||
{ | ||
assert(result[bytes] == 0); | ||
free(result); | ||
} | ||
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
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