aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlfred Perlstein <alfred@fb.com>2017-01-25 17:39:56 -0800
committerAlfred Perlstein <alfred@fb.com>2017-01-25 17:39:56 -0800
commit008e985bc2303999e24d9f2c31934f17485f447e (patch)
treee897903eb2f419fbdf9d25753114451bfc738f39
parent4f818588c7f3125d4cdf91a455c3fe13b11ed482 (diff)
downloadmcelog-008e985bc2303999e24d9f2c31934f17485f447e.tar.gz
Return -ENOMEM for vasprintf in sysfs_write
-rw-r--r--memutil.c14
-rw-r--r--memutil.h1
-rw-r--r--sysfs.c2
3 files changed, 12 insertions, 5 deletions
diff --git a/memutil.c b/memutil.c
index f08d8a0..dd9631c 100644
--- a/memutil.c
+++ b/memutil.c
@@ -62,15 +62,21 @@ char *xstrdup(char *str)
return str;
}
-/* Override weak glibc version */
+int xvasprintf(char **strp, const char *fmt, va_list ap)
+{
+ int n;
+ n = vasprintf(strp, fmt, ap);
+ if (n < 0)
+ Enomem();
+ return n;
+}
+
int asprintf(char **strp, const char *fmt, ...)
{
int n;
va_list ap;
va_start(ap, fmt);
- n = vasprintf(strp, fmt, ap);
+ n = xvasprintf(strp, fmt, ap);
va_end(ap);
- if (n < 0)
- Enomem();
return n;
}
diff --git a/memutil.h b/memutil.h
index 1214585..cff4602 100644
--- a/memutil.h
+++ b/memutil.h
@@ -1,5 +1,6 @@
#include <stdlib.h>
+int xvasprintf(char **ret, const char *format, va_list ap);
void *xalloc(size_t size);
void *xalloc_nonzero(size_t size);
void *xrealloc(void *old, size_t size);
diff --git a/sysfs.c b/sysfs.c
index dfc8a75..3f2d651 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -100,7 +100,7 @@ int sysfs_write(const char *name, const char *fmt, ...)
if (fd < 0)
return -1;
va_start(ap, fmt);
- n = vasprintf(&buf, fmt, ap);
+ n = xvasprintf(&buf, fmt, ap);
va_end(ap);
n = write(fd, buf, n);
e = errno;