Index: code/game/bg_lib.c =================================================================== --- code/game/bg_lib.c (revision 1489) +++ code/game/bg_lib.c (working copy) @@ -1759,10 +1759,11 @@ /* this is really crappy */ int sscanf( const char *buffer, const char *fmt, ... ) { int cmd; - int **arg; + va_list ap; int count; + size_t len; - arg = (int **)&fmt + 1; + va_start (ap, fmt); count = 0; while ( *fmt ) { @@ -1771,22 +1772,40 @@ continue; } - cmd = fmt[1]; - fmt += 2; + fmt++; + cmd = *fmt; + if (isdigit (cmd)) { + len = (size_t)_atoi (&fmt); + cmd = *(fmt - 1); + } else { + len = MAX_STRING_CHARS - 1; + fmt++; + } + switch ( cmd ) { case 'i': case 'd': case 'u': - **arg = _atoi( &buffer ); + *(va_arg (ap, int *)) = _atoi( &buffer ); break; case 'f': - *(float *)*arg = _atof( &buffer ); + *(va_arg (ap, float *)) = _atof( &buffer ); break; + case 's': + { + char *s = va_arg (ap, char *); + while (isspace (*buffer)) + buffer++; + while (*buffer && !isspace (*buffer) && len-- > 0 ) + *s++ = *buffer++; + *s++ = '\0'; + break; + } } - arg++; } + va_end (ap); return count; }