diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2023-10-05 14:48:50 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2023-10-08 21:08:27 +0200 |
commit | a492e287e5d5d2b888e5f2580b4e9e41b6057a05 (patch) | |
tree | f25e7b3995953e0e01cdc9133f839bc5298f266b /util/cutils.c | |
parent | 24f9c07ac0b6acc38b8790b101d32944a2b64739 (diff) | |
download | qemu-a492e287e5d5d2b888e5f2580b4e9e41b6057a05.zip qemu-a492e287e5d5d2b888e5f2580b4e9e41b6057a05.tar.gz qemu-a492e287e5d5d2b888e5f2580b4e9e41b6057a05.tar.bz2 |
cutils: squelch compiler warnings with custom paths
Setting --bindir= to an absolute path that is shorter than the
prefix causes GCC to complain about array accesses out of bounds.
The code however is safe, so disable the warning and explain why
we are doing so.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util/cutils.c')
-rw-r--r-- | util/cutils.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/util/cutils.c b/util/cutils.c index 2537319..3856e30 100644 --- a/util/cutils.c +++ b/util/cutils.c @@ -1012,8 +1012,17 @@ int qemu_pstrcmp0(const char **str1, const char **str2) static inline bool starts_with_prefix(const char *dir) { size_t prefix_len = strlen(CONFIG_PREFIX); + /* + * dir[prefix_len] is only accessed if the length of dir is + * >= prefix_len, so no out of bounds access is possible. + */ +#pragma GCC diagnostic push +#if !defined(__clang__) || __has_warning("-Warray-bounds=") +#pragma GCC diagnostic ignored "-Warray-bounds=" +#endif return !memcmp(dir, CONFIG_PREFIX, prefix_len) && (!dir[prefix_len] || G_IS_DIR_SEPARATOR(dir[prefix_len])); +#pragma GCC diagnostic pop } /* Return the next path component in dir, and store its length in *p_len. */ |