f.zz.de
posts /

Code minimizer

Posted Thu 06 Nov 2014 02:44:17 PM CET
in

Just stumpled upon a very strange bug in perls 'use Switch' which is outdated but it struck me. Most likely this is the most strange bug i ever encountered.

I had ~400 lines of perl code and i couldnt find the exact cause of the bug nor the real lines which were involved so i wrote this which brought the code from 400 to 20 lines which i could then bring down to 12 lines resulting in #768318 in the Debian bug tracker.

Minimal testcase in under 5 minutes.

#!/bin/bash

code="t"

while true; do
        lines=`wc -l<${code}`
        ld=$[ $RANDOM % $lines ]

        cat ${code} | sed -e "${ld},${ld}d" >${code}.tmp
        chmod 755 ${code}.tmp

        ./${code}.tmp >err 2>&1

        #syntax error at ./t.tmp line 139, near "}continue"

        elines=$(wc -l <err)

        if [ $elines -ne 2 ]; then
                continue
        fi

        head -1 err | grep -q "syntax error at .* line .*, near .}continue."

        if [ $? -ne 0 ]; then
                continue
        fi

        mv ${code}.tmp ${code}
done