diff options
author | Albert Astals Cid <aacid@kde.org> | 2022-05-12 22:42:02 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2022-05-12 22:42:02 +0200 |
commit | 4eeb3380ea77d277ace735f191f303564a25a0e3 (patch) | |
tree | 201d5df925234b1f6676871be5ebe68dde4d47a0 | |
parent | e7f0fd89d937d28a77539fb9782a2b59eb51e5a8 (diff) |
greallocn: Make gcc 12.1 happier
Without this hint that bytes is always going to be > 0 we got a million
of warnings like
In function ‘void gfree(void*)’,
inlined from ‘void* greallocn(void*, int, int, bool, bool)’ at goo/gmem.h:178:14,
inlined from ‘void CharCodeToUnicode::setMapping(CharCode, Unicode*, int)’ at poppler/CharCodeToUnicode.cc:648:60:
goo/gmem.h:65:14: warning: pointer used after ‘void free(void*)’ [-Wuse-after-free]
65 | std::free(p);
| ~~~~~~~~~^~~
In function ‘void gfree(void*)’,
inlined from ‘void* grealloc(void*, size_t, bool)’ at goo/gmem.h:73:14,
inlined from ‘void* greallocn(void*, int, int, bool, bool)’ at goo/gmem.h:174:27,
inlined from ‘void CharCodeToUnicode::setMapping(CharCode, Unicode*, int)’ at poppler/CharCodeToUnicode.cc:648:60:
goo/gmem.h:65:14: note: call to ‘void free(void*)’ here
65 | std::free(p);
| ~~~~~~~~~^~~
-rw-r--r-- | goo/gmem.h | 4 |
1 files changed, 3 insertions, 1 deletions
@@ -14,7 +14,7 @@ // under GPL version 2 or later // // Copyright (C) 2005 Takashi Iwai <tiwai@suse.de> -// Copyright (C) 2007-2010, 2017, 2019 Albert Astals Cid <aacid@kde.org> +// Copyright (C) 2007-2010, 2017, 2019, 2022 Albert Astals Cid <aacid@kde.org> // Copyright (C) 2008 Jonathan Kew <jonathan_kew@sil.org> // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de> // Copyright (C) 2021 Even Rouault <even.rouault@spatialys.com> @@ -27,6 +27,7 @@ #ifndef GMEM_H #define GMEM_H +#include <cassert> #include <cstring> #include <cstdlib> #include <cstdio> @@ -169,6 +170,7 @@ inline void *greallocn(void *p, int count, int size, bool checkoverflow = false, std::abort(); } + assert(bytes > 0); if (void *q = grealloc(p, bytes, checkoverflow)) { return q; } |