Add the WARN_UNUSED_RESULT attribute to all hash functions.
authorJohn Darrington <john@darrington.wattle.id.au>
Tue, 21 May 2019 12:30:46 +0000 (14:30 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Tue, 21 May 2019 12:30:46 +0000 (14:30 +0200)
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.

src/data/value-labels.h
src/data/value.h
src/libpspp/hash-functions.h
src/libpspp/i18n.h
src/libpspp/sparse-xarray.h
src/math/interaction.h

index af98d9f9b54ef392f7623f7a3f3d050bb60b5bfb..61a42cff23f973a17c7f3aa974da48dea894f65b 100644 (file)
@@ -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 */
index b1b27ed16eae86b938a99e5db3b2f45d89bafb36..299187285ad5843cd9fc9b549e053a9ebcfde769 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef DATA_VALUE_H
 #define DATA_VALUE_H 1
 
+#include "libpspp/compiler.h"
 #include <assert.h>
 #include <stdbool.h>
 #include <stdlib.h>
@@ -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);
index f792ba2a96eb50b079f1acec0414d9dbfd19f7ea..6fb339be31acd8dbaf841178658cfc2448629a27 100644 (file)
 #ifndef LIBPSPP_HASH_FUNCTIONS_H
 #define LIBPSPP_HASH_FUNCTIONS_H 1
 
+#include "libpspp/compiler.h"
 #include <stddef.h>
 
-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 */
index 5170c50f0d13df77abd8d01537ec4a32afa77e06..d128fcea1a68015eeda204c07056ec0accf36b97 100644 (file)
@@ -17,6 +17,7 @@
 #ifndef I18N_H
 #define I18N_H
 
+#include "libpspp/compiler.h"
 #include <stdbool.h>
 #include <unistr.h>
 
@@ -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 *);
index 15ba49f60c8dc9d555c4f5f477d2ad803f83bc3a..3b3de958b96e1f4d2732241c6fcbec119dc32aa9 100644 (file)
@@ -41,6 +41,7 @@
 #ifndef LIBPSPP_SPARSE_XARRAY_H
 #define LIBPSPP_SPARSE_XARRAY_H 1
 
+#include "libpspp/compiler.h"
 #include <stddef.h>
 #include <stdbool.h>
 
@@ -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 */
index ec6f88b03b6dc06571a9413d73843b1bfbea97df..8229083f860f7cf0a7b86e5f4268b9a1551623cf 100644 (file)
@@ -19,6 +19,7 @@
 #define _INTERACTION_H__ 1
 
 #include <stdbool.h>
+#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 *,