diff options
author | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-05-14 22:19:07 +0200 |
---|---|---|
committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2019-05-14 23:23:08 +0200 |
commit | d8b87afe7c5fcee9caaef7124d5bcd5f0c3af8a1 (patch) | |
tree | ca07ea6097ec12120806ff4c7bd268b9fc063842 /tools/coccinelle | |
parent | Merge pull request #4335 from opensourcerouting/zebra-fpm-blackhole-info (diff) | |
download | frr-d8b87afe7c5fcee9caaef7124d5bcd5f0c3af8a1.tar.xz frr-d8b87afe7c5fcee9caaef7124d5bcd5f0c3af8a1.zip |
lib: hashing functions should take const arguments
It doesn't make much sense for a hash function to modify its argument,
so const the hash input.
BGP does it in a couple places, those cast away the const. Not great but
not any worse than it was.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'tools/coccinelle')
-rw-r--r-- | tools/coccinelle/hash_const.cocci | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/tools/coccinelle/hash_const.cocci b/tools/coccinelle/hash_const.cocci new file mode 100644 index 000000000..9c53cb01f --- /dev/null +++ b/tools/coccinelle/hash_const.cocci @@ -0,0 +1,76 @@ +// +// Transition hash key signatures to take their argument as const. +// Does not handle headers or weirdly named hash functions. +// +@noconst disable optional_qualifier@ +identifier A; +identifier func =~ ".*key$|.*key_make$|.*hash_make$|.*hash_keymake$|.*hash_key$|.*hash_key.*"; +@@ + +- func (void *A) ++ func (const void *A) + { ... } + +@ depends on noconst disable optional_qualifier @ +identifier noconst.A; +identifier noconst.func; +identifier b; +type T; +@@ + +func( ... ) { +<... +- T b = A; ++ const T b = A; +...> + } + +@ depends on noconst disable optional_qualifier @ +identifier noconst.A; +identifier noconst.func; +identifier b; +type T; +@@ + +func(...) + { +<... +- T b = (T) A; ++ const T b = A; +...> + } + +@ depends on noconst disable optional_qualifier @ +identifier noconst.A; +identifier noconst.func; +identifier b; +type T; +@@ + +func(...) + { +<... +- T b; ++ const T b; +... + b = A; +...> + } + +@ depends on noconst disable optional_qualifier @ +identifier noconst.A; +identifier noconst.func; +identifier b; +type T; +@@ + +func(...) + { +<... +- T b; ++ const T b; +... +- b = (T) A; ++ b = A; +...> + } |