fix a segmentation fault and add warning