fix bugs in skin load code

This commit is contained in:
Rudolf Polzer 2010-10-01 12:13:36 +02:00
parent 5c389d3f8a
commit 8ff9eafc50
2 changed files with 8 additions and 9 deletions

View File

@ -271,7 +271,7 @@ void FPrintf (int flag, char *buf)
static qboolean bGotXML = qfalse; static qboolean bGotXML = qfalse;
char level[2]; char level[2];
printf(buf); printf("%s", buf);
// the following part is XML stuff only.. but maybe we don't want that message to go down the XML pipe? // the following part is XML stuff only.. but maybe we don't want that message to go down the XML pipe?
if (flag == SYS_NOXML) if (flag == SYS_NOXML)

View File

@ -242,13 +242,13 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
skinfilename[sizeof(skinfilename)-1] = 0; skinfilename[sizeof(skinfilename)-1] = 0;
skinfilehandle = fopen(skinfilename, "r"); skinfilehandle = fopen(skinfilename, "r");
skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0); skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0);
if(skinfilesize < 0) if(skinfilesize < 0 && skin != 0)
{ {
/* fallback to skin 0 if invalid */ /* fallback to skin 0 if invalid */
snprintf(skinfilename, sizeof(skinfilename), "%s_0.skin", name); snprintf(skinfilename, sizeof(skinfilename), "%s_0.skin", name);
skinfilename[sizeof(skinfilename)-1] = 0; skinfilename[sizeof(skinfilename)-1] = 0;
skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0); skinfilesize = vfsLoadFile(skinfilename, (void**) &skinfilecontent, 0);
if(skinfilesize < 0) if(skinfilesize >= 0)
Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name ); Sys_Printf( "Skin %d of %s does not exist, using 0 instead\n", skin, name );
} }
sf = NULL; sf = NULL;
@ -280,16 +280,15 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
sf = safe_malloc( sizeof( *sf ) ); sf = safe_malloc( sizeof( *sf ) );
sf->next = sf2; sf->next = sf2;
sprintf(format, "replace %%%ds %%%ds%%n", (int)sizeof(sf->name)-1, (int)sizeof(sf->to)-1); sprintf(format, "replace %%%ds %%%ds", (int)sizeof(sf->name)-1, (int)sizeof(sf->to)-1);
pos = 0; if(sscanf(skinfileptr, format, sf->name, sf->to) == 2)
if(sscanf(skinfileptr, format, &sf->name, &sf->to, &pos) > 0 && pos > 0)
continue; continue;
sprintf(format, "%%%ds,%%%ds%%n", (int)sizeof(sf->name)-1, (int)sizeof(sf->to)-1); sprintf(format, " %%%d[^, ] ,%%%ds", (int)sizeof(sf->name)-1, (int)sizeof(sf->to)-1);
pos = 0; if((pos = sscanf(skinfileptr, format, sf->name, sf->to)) == 2)
if(sscanf(skinfileptr, format, &sf->name, &sf->to, &pos) > 0 && pos > 0)
continue; continue;
/* invalid input line -> discard sf struct */ /* invalid input line -> discard sf struct */
Sys_Printf( "Discarding skin directive in %s: %s\n", skinfilename, skinfileptr );
free(sf); free(sf);
sf = sf2; sf = sf2;
} }