From 5226905538ae7ad41b4f3f026c13e3f108318aac Mon Sep 17 00:00:00 2001 From: buslov Date: Mon, 30 Oct 2017 20:54:13 +0300 Subject: [PATCH] Fix V575 warning from PVS-Studio Static Analyzer The potential null pointer is passed into 'sprintf' function. --- src/sym.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/sym.c b/src/sym.c index 35fb268..42fb463 100644 --- a/src/sym.c +++ b/src/sym.c @@ -232,9 +232,11 @@ const char* symTagGetStr (symTag tag) { else if (tag == symParam) return "parameter"; else { char* str = malloc(logi(tag, 10)+2); - sprintf(str, "%d", tag); - debugErrorUnhandled("symTagGetStr", "symbol tag", str); - free(str); + if (str) { + sprintf(str, "%d", tag); + debugErrorUnhandled("symTagGetStr", "symbol tag", str); + free(str); + } return ""; } } @@ -246,9 +248,11 @@ const char* storageTagGetStr (storageTag tag) { else if (tag == storageExtern) return "storageExtern"; else { char* str = malloc(logi(tag, 10)+2); - sprintf(str, "%d", tag); - debugErrorUnhandled("storageTagGetStr", "storage tag", str); - free(str); + if (str) { + sprintf(str, "%d", tag); + debugErrorUnhandled("storageTagGetStr", "storage tag", str); + free(str); + } return ""; } }