-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix string truncation warnings related to PATH_MAX
There are a number of places where rrdtool combines multiple PATH_MAX sized strings into one. PATH_MAX is a constant that tends to work in practice a lot of the time but may not reflect the real capabilities of the system in real time. In place of on-stack buffers of PATH_MAX size allocate memory dynamically. Initialize the pointers to NULL so they can be all freed unconditionally on exit. Fixes: #1223 Signed-off-by: Michal Suchanek <[email protected]>
- Loading branch information
Showing
4 changed files
with
122 additions
and
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef H_RRDTOOL_SRC_COMPAT_ASPRINTF_H | ||
#define H_RRDTOOL_SRC_COMPAT_ASPRINTF_H | ||
|
||
#include <rrd_config.h> | ||
#include <stdio.h> | ||
|
||
#ifndef HAVE_ASPRINTF | ||
#include <stdarg.h> | ||
|
||
static inline | ||
int asprintf(char **result, const char *format, ...) | ||
{ | ||
va_list ap; | ||
va_list aq; | ||
int size; | ||
char *buffer; | ||
|
||
va_start(ap, format); | ||
va_copy(aq, ap); | ||
size = vsnprintf(NULL, 0, format, ap); | ||
if (size < 0) | ||
return size; | ||
size++; | ||
buffer = malloc(size); | ||
if (!buffer) | ||
return -ENOMEM; | ||
*result = buffer; | ||
size = vsnprintf(buffer, size, format, aq); | ||
va_end(ap); | ||
return size; | ||
} | ||
|
||
#endif /* HAVE_ASPRINTF */ | ||
|
||
#endif /* H_RRDTOOL_SRC_COMPAT_ASPRINTF_H */ |
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