you should use 'memcpy'  instead of strcpy because there is no guaranty that msg has '\0'.