mirror of
https://github.com/martijnvanbrummelen/nwipe.git
synced 2026-02-20 05:32:14 +00:00
Improve str_truncate
Check start_column < wcols and issue error Reduce output length by 1 to take care a situation where output_length maybe provided by strlen which excludes the null terminator and sizeof which may or may count the terminator.
This commit is contained in:
committed by
Fabian Druschke
parent
fea3d8c303
commit
f6840105b0
10
src/gui.c
10
src/gui.c
@@ -8257,16 +8257,22 @@ char* str_truncate( int wcols, int start_column, const char* input, char* output
|
||||
*/
|
||||
|
||||
int length, idx = 0;
|
||||
|
||||
if( start_column < wcols )
|
||||
{
|
||||
length = wcols - start_column - 1;
|
||||
idx = 0;
|
||||
while( idx < output_length && idx < length )
|
||||
while( idx < output_length - 1 && idx < length && input[idx] != 0 )
|
||||
{
|
||||
output[idx] = input[idx];
|
||||
idx++;
|
||||
}
|
||||
/* terminate the string */
|
||||
output[idx] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
strncpy( output, "Error:start_column>=wcols", output_length - 1 );
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user