aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Paland <marco@paland.com>2018-05-12 01:15:25 +0200
committerMarco Paland <marco@paland.com>2018-05-12 01:15:25 +0200
commitee383ad5c7b5bbf60b4af447c5114e95a734688d (patch)
tree12b54df529b9de780f73de37572edbc896203611
parent277aa259fcfa3fb4f6a92c6d8832453ae693b869 (diff)
downloadprintf-ee383ad5c7b5bbf60b4af447c5114e95a734688d.tar.gz
printf-ee383ad5c7b5bbf60b4af447c5114e95a734688d.tar.bz2
printf-ee383ad5c7b5bbf60b4af447c5114e95a734688d.zip
fix(printf): use C conform `NULL` instead of C++ `nullptr`
Fixes #14
-rw-r--r--README.md9
-rw-r--r--printf.c2
2 files changed, 6 insertions, 5 deletions
diff --git a/README.md b/README.md
index 5d03f03..1e2af49 100644
--- a/README.md
+++ b/README.md
@@ -52,10 +52,6 @@ int snprintf(char* buffer, size_t count, const char* format, ...);
int vsnprintf(char* buffer, size_t count, const char* format, va_list va);
```
-If `buffer` is set to `nullptr` nothing is written and just the formatted length is returned.
-```C
-int length = sprintf(nullptr, "Hello, world"); // length is set to 12
-```
**Due to genaral security reasons it is highly recommended to prefer and use `snprintf` (with the max buffer size as `count` parameter) instead of `sprintf`.**
`sprintf` has no buffer limitation, so when needed - use it really with care!
@@ -136,6 +132,11 @@ Notice that a value equal or larger than `count` indicates a truncation. Only wh
the string has been completely written.
If any error is encountered, `-1` is returned.
+If `buffer` is set to `NULL` (`nullptr`) nothing is written and just the formatted length is returned.
+```C
+int length = sprintf(NULL, "Hello, world"); // length is set to 12
+```
+
## Compiler switches/defines
diff --git a/printf.c b/printf.c
index 8fe7048..56f60d6 100644
--- a/printf.c
+++ b/printf.c
@@ -647,7 +647,7 @@ int printf(const char* format, ...)
{
va_list va;
va_start(va, format);
- const int ret = _vsnprintf(_out_char, nullptr, (size_t)-1, format, va);
+ const int ret = _vsnprintf(_out_char, NULL, (size_t)-1, format, va);
va_end(va);
return ret;
}