util-linux/tools/checkxalloc.sh
Dave Reisner 99d618c0eb checkxalloc: nudge regex, fix newfound instances
Using the -w flag with grep actually fought against us here, and hid
some instances where xalloc functions weren't used. Discard it in
favor of an explicit word boundary as a prefix to the function name,
and extend our requirements on the trailing side of the pattern.

This also fixes the few new instances that were overlooked because of
the regex's deficiency.

[kzak@redhat.com: - fix also newfound in findmnt
                  - remove unnecessary checks after xallocs]

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-20 09:44:40 +01:00

24 lines
457 B
Bash
Executable File

#!/bin/sh
#
# Find files which include the xalloc.h header, but which still call
# the unwrapped calloc and malloc.
#
cd "$(git rev-parse --show-toplevel)" || {
echo "error: failed to chdir to git root"
exit 1
}
git grep -zl '#include "xalloc.h"' |
xargs -0 grep -nE '\b(([cm]|re)alloc|strdup|asprintf)[[:space:]]*\([^)]'
result=$?
if [ $result -eq 123 ]; then
exit 0 # not found
elif [ $result -eq 0 ]; then
exit 1 # found
fi
exit $result