prevent filename overflow in model .skin loader
strip model extension during filename construction add variadic template operator to StringOutputStream for inline strings creation
This commit is contained in:
parent
cfa502df6e
commit
3b39a5754d
|
|
@ -112,6 +112,14 @@ std::size_t write( const char* buffer, std::size_t length ){
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<typename ... Args>
|
||||||
|
StringOutputStream& operator()( const Args& ... args ){
|
||||||
|
clear();
|
||||||
|
using expander = int[];
|
||||||
|
(void)expander{ 0, ( (void)( *this << args ), 0 ) ... };
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
iterator begin(){
|
iterator begin(){
|
||||||
return m_string.begin();
|
return m_string.begin();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -224,7 +224,6 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
|
||||||
byte *color;
|
byte *color;
|
||||||
picoIndex_t *indexes;
|
picoIndex_t *indexes;
|
||||||
skinfile_t *sf, *sf2;
|
skinfile_t *sf, *sf2;
|
||||||
char skinfilename[ MAX_QPATH ];
|
|
||||||
char *skinfilecontent;
|
char *skinfilecontent;
|
||||||
int skinfilesize;
|
int skinfilesize;
|
||||||
char *skinfileptr, *skinfilenextptr;
|
char *skinfileptr, *skinfilenextptr;
|
||||||
|
|
@ -246,14 +245,12 @@ void InsertModel( const char *name, int skin, int frame, m4x4_t transform, remap
|
||||||
}
|
}
|
||||||
|
|
||||||
/* load skin file */
|
/* load skin file */
|
||||||
snprintf( skinfilename, sizeof( skinfilename ), "%s_%d.skin", name, skin );
|
auto skinfilename = StringOutputStream(99)( StringRange( name, path_get_filename_base_end( name ) ), '_', skin, ".skin" );
|
||||||
skinfilename[sizeof( skinfilename ) - 1] = 0;
|
skinfilesize = vfsLoadFile( skinfilename.c_str(), (void**) &skinfilecontent, 0 );
|
||||||
skinfilesize = vfsLoadFile( skinfilename, (void**) &skinfilecontent, 0 );
|
|
||||||
if ( skinfilesize < 0 && skin != 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 );
|
skinfilename( StringRange( name, path_get_filename_base_end( name ) ), "_0.skin" );
|
||||||
skinfilename[sizeof( skinfilename ) - 1] = 0;
|
skinfilesize = vfsLoadFile( skinfilename.c_str(), (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 );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,7 @@
|
||||||
#include "md4.h"
|
#include "md4.h"
|
||||||
|
|
||||||
#include "stringfixedsize.h"
|
#include "stringfixedsize.h"
|
||||||
|
#include "stream/stringstream.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user