A malloc that contains multiplication that migth overflow could be converted to one that does not almost automatically (unless user is so clever that he can utilize overflow.)
This is not patch but a patch generator, it could be used to produce patch for each project that uses malloc. For conversion you need to have http://coccinelle.lip6.fr/ installed. Then run attached nmalloc wrapper script to generate patch. Then if you want to generate changelogs with list of all functions touched you I attached files for changelog generation that are used by running mkchlog and using Log file.
echo "@@ expression e1; type t; @@ - (t *) xmalloca (e1 * sizeof (t)) + XNMALLOCA (e1, t)" > /tmp/xmalloca1.cocci echo "@@ expression e1; type t; @@ - xmalloca (e1 * sizeof (t)) + XNMALLOCA (e1, t)" > /tmp/xmalloca2.cocci echo "@@ expression e1, e2; @@ - xmalloca (e1 * e2) + xnmalloca (e1, e2)" > /tmp/xmalloca3.cocci SPATCHES='/tmp/xmalloca1.cocci /tmp/xmalloca2.cocci /tmp/xmalloca3.cocci' for FILE in `git grep --name-only 'malloca (' | grep 'c$' | grep -v test | grep -v bug`; do echo $FILE for SPATCH in $SPATCHES; do timeout 10s spatch $SPATCH -in_place $FILE 2> /dev/null done done echo "@@ expression e1; type t; @@ - (t *) malloc (e1 * sizeof (t)) + NMALLOC (e1, t)" > /tmp/malloc1.cocci echo "@@ expression e1; type t; @@ - malloc (e1 * sizeof (t)) + NMALLOC (e1, t)" > /tmp/malloc2.cocci echo "@@ expression e1, e2; @@ - malloc (e1 * e2) + nmalloc (e1, e2)" > /tmp/malloc3.cocci SPATCHES='/tmp/malloc1.cocci /tmp/malloc2.cocci /tmp/malloc3.cocci' for FILE in `git grep --name-only 'malloc (' | grep 'c$' | grep -v test | grep -v bug`; do echo $FILE for SPATCH in $SPATCHES; do timeout 10s spatch $SPATCH -in_place $FILE 2> /dev/null done done echo "@@ expression e, e1; type t; @@ - (t *) realloc (e, e1 * sizeof (t)) + NREALLOC (e, e1, t)" > /tmp/realloc1.cocci echo "@@ expression e, e1; type t; @@ - realloc (e, e1 * sizeof (t)) + NREALLOC (e, e1, t)" > /tmp/realloc2.cocci echo "@@ expression e, e1, e2; @@ - realloc (e, e1 * e2) + nrealloc (e, e1, e2)" > /tmp/malloc3.cocci SPATCHES='/tmp/realloc1.cocci /tmp/realloc2.cocci /tmp/realloc3.cocci' for FILE in `git grep --name-only 'realloc (' | grep 'c$' | grep -v test | grep -v bug`; do echo $FILE for SPATCH in $SPATCHES; do timeout 10s spatch $SPATCH -in_place $FILE 2> /dev/null done done git diff | sed -e "s/^+\(.*[a-zA-Z0-9_]\)(/+\1 (/" > diff git checkout -f git apply diff
#!/bin/bash rm Log 2> /dev/null TMP=`mktemp` echo "`date +%Y-%m-%d` `git log --pretty="%an <%ae>" | head -n 1`" > Log echo >> Log for FILE in `git diff --name-only`; do git diff $FILE > $TMP FNS=`perl diff.pl $TMP $FILE` echo "\t* $FILE ($FNS): Likewise." >> Log done
diff.pl
Description: Perl program
fname.pl
Description: Perl program