fix bug: set the last char to be 0 in mg_read()