diff options
author | Andrey Nazarov <skuller@skuller.net> | 2009-09-05 12:34:05 +0000 |
---|---|---|
committer | Andrey Nazarov <skuller@skuller.net> | 2009-09-05 12:34:05 +0000 |
commit | c1df6019baf94cdec6b1404de69fafce12aa26a4 (patch) | |
tree | 340ff19edbd6c30e76f70c13303e6859833f3bb7 /source/q_shared.c | |
parent | f1d3a7ffd40a0e6768b220cf76d05db3c57c3e89 (diff) |
Changed return type of Info_SubValidate to size_t.
Print more informative warnings when attempting to set an invalid info cvar value.
Diffstat (limited to 'source/q_shared.c')
-rw-r--r-- | source/q_shared.c | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/source/q_shared.c b/source/q_shared.c index 5019256..9a4aea0 100644 --- a/source/q_shared.c +++ b/source/q_shared.c @@ -1183,23 +1183,23 @@ qboolean Info_Validate( const char *s ) { /* ============ -Info_ValidateSubstring +Info_SubValidate ============ */ -int Info_SubValidate( const char *s ) { - const char *start; - int c, len; +size_t Info_SubValidate( const char *s ) { + size_t len; + int c; - for( start = s; *s; s++ ) { - c = *s & 127; + len = 0; + while( *s ) { + c = *s++; + c &= 127; // strip high bits if( c == '\\' || c == '\"' || c == ';' ) { - return -1; + return SIZE_MAX; // illegal characters + } + if( ++len == MAX_QPATH ) { + return MAX_QPATH; // oversize value } - } - - len = s - start; - if( len >= MAX_QPATH ) { - return -1; } return len; @@ -1212,17 +1212,18 @@ Info_SetValueForKey */ qboolean Info_SetValueForKey( char *s, const char *key, const char *value ) { char newi[MAX_INFO_STRING], *v; - int c, l, kl, vl; + size_t l, kl, vl; + int c; // validate key kl = Info_SubValidate( key ); - if( kl == -1 ) { + if( kl >= MAX_QPATH ) { return qfalse; } // validate value vl = Info_SubValidate( value ); - if( vl == -1 ) { + if( vl >= MAX_QPATH ) { return qfalse; } @@ -1231,7 +1232,7 @@ qboolean Info_SetValueForKey( char *s, const char *key, const char *value ) { return qtrue; } - l = ( int )strlen( s ); + l = strlen( s ); if( l + kl + vl + 2 >= MAX_INFO_STRING ) { return qfalse; } |