Skip to contentSkip to conversation

src: gen-image: Fix compiler warning

PATCH In review Paul Elder 2 participants 2 messages Sep 17

lore
Share & tools
lore

Paul Elder

author
#0 lore raw

PATCH 1/1 src: gen-image: Fix compiler warning

Fix compiler warning for maybe uninitialized.

---
 src/gen-image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/gen-image.c +1 -1
index 26d7f0d28417..401e1316ae5a 100644
@@ -386,7 +386,7 @@ static int pnm_read_integer(int fd)
 
 static struct image *pnm_read(const char *filename)
 {
-	struct image *image;
+	struct image *image = NULL;
 	unsigned int width;
 	unsigned int height;
 	char buffer[2];
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw

Hi Paul,

Thank you for the patch.

Quoted 1 line · Paul Elder

Fix compiler warning for maybe uninitialized.

It's useful to record more detailed information when working around compiler issues. I'll expand the commit message to

gcc reports an uninitialized variable when compiling with '-Os':

In function ‘process’,

    inlined from ‘main’ at ../src/gen-image.c:2359:8:

../src/gen-image.c:1722:12: error: ‘image’ may be used uninitialized [-Werror=maybe-uninitialized]
1722 | if (!input) {
| ^
../src/gen-image.c: In function ‘main’:
../src/gen-image.c:389:23: note: ‘image’ was declared here
389 | struct image *image;
| ^~~~~

This appears to be a false positive. Work around it by initializing the image variable to NULL when declaring it.

Quoted 1 line
Quoted 17 lines
---
 src/gen-image.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/gen-image.c +1 -1
index 26d7f0d28417..401e1316ae5a 100644
@@ -386,7 +386,7 @@ static int pnm_read_integer(int fd)
 
 static struct image *pnm_read(const char *filename)
 {
-	struct image *image;
+	struct image *image = NULL;
 	unsigned int width;
 	unsigned int height;
 	char buffer[2];
Signature · 3 lines
Regards,

Laurent Pinchart