From 3488d4e65f85b30d1cb06fc69e297433cb8dd938 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Fri, 18 Nov 2022 21:21:17 +0500 Subject: [PATCH] public: simplified strings operations. --- public/crtlib.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/public/crtlib.c b/public/crtlib.c index 6dba1ec4..34972978 100644 --- a/public/crtlib.c +++ b/public/crtlib.c @@ -560,14 +560,14 @@ char *Q_pretifymem( float value, int digitsafterdecimal ) if( value > onemb ) { value /= onemb; - Q_sprintf( suffix, " Mb" ); + Q_strcpy( suffix, " Mb" ); } else if( value > onekb ) { value /= onekb; - Q_sprintf( suffix, " Kb" ); + Q_strcpy( suffix, " Kb" ); } - else Q_sprintf( suffix, " bytes" ); + else Q_strcpy( suffix, " bytes" ); // clamp to >= 0 digitsafterdecimal = Q_max( digitsafterdecimal, 0 ); @@ -591,8 +591,8 @@ char *Q_pretifymem( float value, int digitsafterdecimal ) o = out; // search for decimal or if it was integral, find the space after the raw number - dot = Q_strstr( i, "." ); - if( !dot ) dot = Q_strstr( i, " " ); + dot = Q_strchr( i, '.' ); + if( !dot ) dot = Q_strchr( i, ' ' ); pos = dot - i; // compute position of dot pos -= 3; // don't put a comma if it's <= 3 long @@ -750,7 +750,7 @@ void COM_ExtractFilePath( const char *path, char *dest ) memcpy( dest, path, src - path ); dest[src - path - 1] = 0; // cutoff backslash } - else Q_strcpy( dest, "" ); // file without path + else dest[0] = 0; // file without path } /* @@ -785,10 +785,12 @@ COM_DefaultExtension void COM_DefaultExtension( char *path, const char *extension ) { const char *src; + size_t len; // if path doesn't have a .EXT, append extension // (extension should include the .) - src = path + Q_strlen( path ) - 1; + len = Q_strlen( path ); + src = path + len - 1; while( *src != '/' && src != path ) { @@ -797,7 +799,7 @@ void COM_DefaultExtension( char *path, const char *extension ) src--; } - Q_strcat( path, extension ); + Q_strcpy( &path[len], extension ); } /*