From: John Darrington Date: Tue, 21 May 2019 12:30:46 +0000 (+0200) Subject: Add the WARN_UNUSED_RESULT attribute to all hash functions. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8765cd7639e64d5dcd8f494aee23babb3b3f179;p=pspp Add the WARN_UNUSED_RESULT attribute to all hash functions. A hash function has no purpose if the result is unused, and tests will typically not pick up a mistake where the programmer forgets to assign the result - the hash table will merely degenerate to a linear searched array. --- diff --git a/src/data/value-labels.h b/src/data/value-labels.h index af98d9f9b5..61a42cff23 100644 --- a/src/data/value-labels.h +++ b/src/data/value-labels.h @@ -114,7 +114,7 @@ const struct val_lab *val_labs_next (const struct val_labs *, const struct val_lab **val_labs_sorted (const struct val_labs *); /* Properties of entire sets. */ -unsigned int val_labs_hash (const struct val_labs *, unsigned int basis); +unsigned int val_labs_hash (const struct val_labs *, unsigned int basis) WARN_UNUSED_RESULT; bool val_labs_equal (const struct val_labs *, const struct val_labs *); #endif /* data/value-labels.h */ diff --git a/src/data/value.h b/src/data/value.h index b1b27ed16e..299187285a 100644 --- a/src/data/value.h +++ b/src/data/value.h @@ -17,6 +17,7 @@ #ifndef DATA_VALUE_H #define DATA_VALUE_H 1 +#include "libpspp/compiler.h" #include #include #include @@ -71,7 +72,7 @@ void value_copy_buf_rpad (union value *dst, int dst_width, void value_set_missing (union value *, int width); int value_compare_3way (const union value *, const union value *, int width); bool value_equal (const union value *, const union value *, int width); -unsigned int value_hash (const union value *, int width, unsigned int basis); +unsigned int value_hash (const union value *, int width, unsigned int basis) WARN_UNUSED_RESULT; bool value_is_resizable (const union value *, int old_width, int new_width); bool value_needs_resize (int old_width, int new_width); diff --git a/src/libpspp/hash-functions.h b/src/libpspp/hash-functions.h index f792ba2a96..6fb339be31 100644 --- a/src/libpspp/hash-functions.h +++ b/src/libpspp/hash-functions.h @@ -17,12 +17,13 @@ #ifndef LIBPSPP_HASH_FUNCTIONS_H #define LIBPSPP_HASH_FUNCTIONS_H 1 +#include "libpspp/compiler.h" #include -unsigned int hash_bytes (const void *, size_t, unsigned int basis); -unsigned int hash_string (const char *, unsigned int basis); -unsigned int hash_int (int, unsigned int basis); -unsigned int hash_double (double, unsigned int basis); -unsigned int hash_pointer (const void *, unsigned int basis); +unsigned int hash_bytes (const void *, size_t, unsigned int basis) WARN_UNUSED_RESULT; +unsigned int hash_string (const char *, unsigned int basis) WARN_UNUSED_RESULT; +unsigned int hash_int (int, unsigned int basis) WARN_UNUSED_RESULT; +unsigned int hash_double (double, unsigned int basis) WARN_UNUSED_RESULT; +unsigned int hash_pointer (const void *, unsigned int basis) WARN_UNUSED_RESULT; #endif /* libpspp/hash-functions.h */ diff --git a/src/libpspp/i18n.h b/src/libpspp/i18n.h index 5170c50f0d..d128fcea1a 100644 --- a/src/libpspp/i18n.h +++ b/src/libpspp/i18n.h @@ -17,6 +17,7 @@ #ifndef I18N_H #define I18N_H +#include "libpspp/compiler.h" #include #include @@ -71,8 +72,8 @@ bool set_encoding_from_locale (const char *loc); const char *uc_name (ucs4_t uc, char buffer[16]); -unsigned int utf8_hash_case_bytes (const char *, size_t n, unsigned int basis); -unsigned int utf8_hash_case_string (const char *, unsigned int basis); +unsigned int utf8_hash_case_bytes (const char *, size_t n, unsigned int basis) WARN_UNUSED_RESULT; +unsigned int utf8_hash_case_string (const char *, unsigned int basis) WARN_UNUSED_RESULT; int utf8_strcasecmp (const char *, const char *); int utf8_strncasecmp (const char *, size_t, const char *, size_t); int utf8_strverscasecmp (const char *, const char *); diff --git a/src/libpspp/sparse-xarray.h b/src/libpspp/sparse-xarray.h index 15ba49f60c..3b3de958b9 100644 --- a/src/libpspp/sparse-xarray.h +++ b/src/libpspp/sparse-xarray.h @@ -41,6 +41,7 @@ #ifndef LIBPSPP_SPARSE_XARRAY_H #define LIBPSPP_SPARSE_XARRAY_H 1 +#include "libpspp/compiler.h" #include #include @@ -67,6 +68,6 @@ bool sparse_xarray_copy (const struct sparse_xarray *src, /* For testing purposes only. */ unsigned int sparse_xarray_model_checker_hash (const struct sparse_xarray *, - unsigned int basis); + unsigned int basis) WARN_UNUSED_RESULT; #endif /* libpspp/sparse-libpspp.h */ diff --git a/src/math/interaction.h b/src/math/interaction.h index ec6f88b03b..8229083f86 100644 --- a/src/math/interaction.h +++ b/src/math/interaction.h @@ -19,6 +19,7 @@ #define _INTERACTION_H__ 1 #include +#include "libpspp/compiler.h" #include "data/missing-values.h" struct ccase; @@ -60,7 +61,8 @@ bool interaction_is_subset (const struct interaction *, unsigned int interaction_case_hash (const struct interaction *, - const struct ccase *, unsigned int base); + const struct ccase *, + unsigned int base) WARN_UNUSED_RESULT; bool interaction_case_equal (const struct interaction *, const struct ccase *, const struct ccase *); bool interaction_case_is_missing (const struct interaction *,