]> git.droids-corp.org - dpdk.git/blobdiff - lib/librte_eal/windows/eal/include/rte_os.h
eal/windows: fix out-of-memory check in asprintf
[dpdk.git] / lib / librte_eal / windows / eal / include / rte_os.h
index 9e762617b1980d728df4fc8a05d67b349c7adb21..c76be12168464f0dbea745f2c744e80e8ca198aa 100644 (file)
@@ -64,12 +64,15 @@ asprintf(char **buffer, const char *format, ...)
        va_list arg;
 
        va_start(arg, format);
-       size = vsnprintf(NULL, 0, format, arg) + 1;
+       size = vsnprintf(NULL, 0, format, arg);
        va_end(arg);
+       if (size < 0)
+               return -1;
+       size++;
 
        *buffer = malloc(size);
-       if (buffer == NULL)
-               printf("Cannot allocate memory");
+       if (*buffer == NULL)
+               return -1;
 
        va_start(arg, format);
        ret = vsnprintf(*buffer, size, format, arg);