From ec290c412087c1ae45252a252e1bff799c22da06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gunter=20K=C3=B6nigsmann?= Date: Mon, 23 Dec 2019 22:35:16 +0100 Subject: [PATCH] Resolved the cppcheck style warnings cppcheck is a popular tool that performs static code analysis outputting warnings if constructs are error-prone or do not make sense. Currently nanosvg produces many warnings, though, making spotting real errors in a project harder than necessary. This commit resolves the following warings: nanosvg.h:829: style: Variable 'data' is reassigned a value before the old one has been used. nanosvg.h:2907: style: Variable 'fp' is reassigned a value before the old one has been used. The cause of these warnings is that both variables are set to NULL and then assigned a different value to - which is no bug but adds an unnecessary assignment to the code. --- src/nanosvg.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/nanosvg.h b/src/nanosvg.h index e5f69006..2ecbffb5 100644 --- a/src/nanosvg.h +++ b/src/nanosvg.h @@ -819,14 +819,13 @@ static NSVGgradientData* nsvg__findGradientData(NSVGparser* p, const char* id) static NSVGgradient* nsvg__createGradient(NSVGparser* p, const char* id, const float* localBounds, char* paintType) { NSVGattrib* attr = nsvg__getAttr(p); - NSVGgradientData* data = NULL; NSVGgradientData* ref = NULL; NSVGgradientStop* stops = NULL; NSVGgradient* grad; float ox, oy, sw, sh, sl; int nstops = 0; - data = nsvg__findGradientData(p, id); + NSVGgradientData* data = nsvg__findGradientData(p, id); if (data == NULL) return NULL; // TODO: use ref to fill in all unset values too. @@ -2899,12 +2898,11 @@ NSVGimage* nsvgParse(char* input, const char* units, float dpi) NSVGimage* nsvgParseFromFile(const char* filename, const char* units, float dpi) { - FILE* fp = NULL; size_t size; char* data = NULL; NSVGimage* image = NULL; - fp = fopen(filename, "rb"); + FILE* fp = fopen(filename, "rb"); if (!fp) goto error; fseek(fp, 0, SEEK_END); size = ftell(fp);