@@ -380,7 +380,7 @@ int main( int argc, char ** argv )
380
380
{
381
381
uint8_t buffer [256 ];
382
382
#if TERMINAL_INPUT_BUFFER
383
- char print_buf [300 ]; // Buffer that is filled with everything and will be written to stdout (basically it's for formatting)
383
+ char print_buf [TERMINAL_BUFFER_SIZE ]; // Buffer that is filled with everything and will be written to stdout (basically it's for formatting)
384
384
uint8_t update = 0 ;
385
385
#endif
386
386
if ( !IsGDBServerInShadowHaltState ( dev ) )
@@ -417,17 +417,11 @@ int main( int argc, char ** argv )
417
417
}
418
418
if ( to_send == 0 )
419
419
{
420
- strcpy ( print_buf , TERMINAL_CLEAR_CUR );
421
- strcat ( print_buf , TERMIANL_INPUT_SENT );
422
- strcat ( print_buf , input_buf );
423
- strcat ( print_buf , "\n" );
424
- strcat ( print_buf , pline_buf );
425
- strcat ( print_buf , TERMINAL_SEND_LABEL );
420
+ snprintf (print_buf , TERMINAL_BUFFER_SIZE - 1 , "%s%s%s\n%s%s" , TERMINAL_CLEAR_CUR , TERMIANL_INPUT_SENT , input_buf , pline_buf , TERMINAL_SEND_LABEL );
426
421
fwrite ( print_buf , strlen ( print_buf ), 1 , stdout );
427
422
fflush ( stdout );
428
423
input_pos = 0 ;
429
- input_buf [0 ] = 0 ;
430
- // memset( input_buf, 0, sizeof( input_buf ) );
424
+ memset ( input_buf , 0 , sizeof ( input_buf ) );
431
425
}
432
426
appendword |= i + 4 ;
433
427
}
@@ -448,10 +442,10 @@ int main( int argc, char ** argv )
448
442
#if TERMINAL_INPUT_BUFFER
449
443
if ( ( r == -1 || r == 0 ) && update > 0 )
450
444
{
451
- strcpy ( print_buf , TERMINAL_CLEAR_CUR );
452
- if ( to_send > 0 ) strcat ( print_buf , TERMINAL_DIM );
453
- strcat ( print_buf , TERMINAL_SEND_LABEL );
454
- strcat ( print_buf , input_buf );
445
+ strncpy ( print_buf , TERMINAL_CLEAR_CUR , TERMINAL_BUFFER_SIZE - 1 );
446
+ if ( to_send > 0 ) strncat ( print_buf , TERMINAL_DIM , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) );
447
+ strncat ( print_buf , TERMINAL_SEND_LABEL , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) );
448
+ strncat ( print_buf , input_buf , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) );
455
449
fwrite ( print_buf , strlen ( print_buf ), 1 , stdout );
456
450
fflush ( stdout );
457
451
}
@@ -471,13 +465,13 @@ int main( int argc, char ** argv )
471
465
#if TERMINAL_INPUT_BUFFER
472
466
uint8_t new_line = 0 ;
473
467
if ( buffer [r - 1 ] == '\n' ) new_line = 1 ;
474
- if ( new_line == 0 ) strcpy ( print_buf , TERMINAL_CLEAR_PREV ); // Go one line up and erase it
475
- else strcpy ( print_buf , TERMINAL_CLEAR_CUR ); // Go to the start of the line and erase it
476
- strncat ( pline_buf , (char * )buffer , r ); // Add newely received chars to line buffer
477
- strcat ( print_buf , pline_buf ); // Add line to buffer
478
- if ( to_send > 0 ) strcat ( print_buf , TERMINAL_DIM );
479
- strcat ( print_buf , TERMINAL_SEND_LABEL ); // Print styled "Send" label
480
- strcat ( print_buf , input_buf ); // Print current input
468
+ if ( new_line == 0 ) strncpy ( print_buf , TERMINAL_CLEAR_PREV , TERMINAL_BUFFER_SIZE - 1 ); // Go one line up and erase it
469
+ else strncpy ( print_buf , TERMINAL_CLEAR_CUR , TERMINAL_BUFFER_SIZE - 1 ); // Go to the start of the line and erase it
470
+ strncat ( pline_buf , (char * )buffer , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) ); // Add newely received chars to line buffer
471
+ strncat ( print_buf , pline_buf , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) ); // Add line to buffer
472
+ if ( to_send > 0 ) strncat ( print_buf , TERMINAL_DIM , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) );
473
+ strncat ( print_buf , TERMINAL_SEND_LABEL , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) ); // Print styled "Send" label
474
+ strncat ( print_buf , input_buf , TERMINAL_BUFFER_SIZE - 1 - strlen ( print_buf ) ); // Print current input
481
475
fwrite ( print_buf , strlen ( print_buf ), 1 , stdout );
482
476
print_buf [0 ] = 0 ;
483
477
if ( new_line == 1 ) pline_buf [0 ] = 0 ;
0 commit comments