lib/generic/pack: switch to NULL on empty pack iterator

It's probably slightly safer to use NULL than end-array pointer,
so let's use it in this case.  Significantly adapted by Vlada
from original Marek's change, after master fixed the corruption.
18 jobs for marek/memory-corruption-fixes
in 8 minutes and 57 seconds and was queued for 12 seconds