fix the bug in sam.c