string-util: add strlen_ptr() helper
strlen_ptr() is to strlen() what streq_ptr() is to streq(): i.e. it handles NULL strings in a smart way.
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#include "alloc-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "macro.h"
|
||||
#include "string-util.h"
|
||||
#include "util.h"
|
||||
|
||||
char octchar(int x) {
|
||||
@@ -569,7 +570,7 @@ static int base64_append_width(char **prefix, int plen,
|
||||
|
||||
lines = (len + width - 1) / width;
|
||||
|
||||
slen = sep ? strlen(sep) : 0;
|
||||
slen = strlen_ptr(sep);
|
||||
t = realloc(*prefix, plen + 1 + slen + (indent + width + 1) * lines);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user