History

updating sprintf() functions to snprintf(); additional changes for type casting consistency

Ge Wang committed 3 years ago

Commit 725e88b1 parent 452dff937 files · +282 −257Browse files

Showing the changes to src/core/chuck_errmsg.cpp (1 of 37 files). Show all

Unified · Split

src/core/chuck_errmsg.cpp+19−18
@@ -51,7 +51,8 @@ t_CKBOOL anyErrors= FALSE; · 50 unmodified lines
5151 // local global
5252 static const char * fileName = "";
5353 static int lineNum = 1;
54−static char g_buffer[1024] = "";
54+#define CK_ERR_BUF_LENGTH 1024
55+static char g_buffer[CK_ERR_BUF_LENGTH] = "";
5556 static const size_t LASTERROR_SIZE = 1024;
5657 static char g_lasterror[LASTERROR_SIZE] = "[chuck]: (no error)";
5758 static size_t g_lasterrorIndex = strlen(g_lasterror);
@@ -367,7 +368,7 @@ static const char * g_str[] = { · 309 unmodified lines
367368
368369
369370 // intList
370−typedef struct intList {int i; struct intList *rest;} *IntList;
371+typedef struct intList {t_CKINT i; struct intList *rest;} *IntList;
371372 static IntList linePos=NULL;
372373
373374
@@ -387,7 +388,7 @@ static int lastErrorCat(const char * str) · 13 unmodified lines
387388
388389
389390 // constructor
390−static IntList intList( int i, IntList rest )
391+static IntList intList( t_CKINT i, IntList rest )
391392 {
392393 IntList l = (IntList)checked_malloc(sizeof *l);
393394 l->i=i; l->rest=rest;
@@ -431,7 +432,7 @@ void EM_reset_msg() · 37 unmodified lines
431432 }
432433
433434 // [%s]:line(%d).char(%d):
434−void EM_error( int pos, const char * message, ... )
435+void EM_error( t_CKINT pos, const char * message, ... )
435436 {
436437 va_list ap;
437438 IntList lines = linePos;
@@ -448,12 +449,12 @@ void EM_error( int pos, const char * message, ... ) · 10 unmodified lines
448449 if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" );
449450
450451 CK_FPRINTF_STDERR( "[%s]:", *fileName ? mini(fileName) : "chuck" );
451− sprintf( g_buffer, "[%s]:", *fileName ? mini(fileName) : "chuck" );
452+ snprintf( g_buffer, CK_ERR_BUF_LENGTH, "[%s]:", *fileName ? mini(fileName) : "chuck" );
452453 lastErrorCat( g_buffer );
453454 if(lines)
454455 {
455456 CK_FPRINTF_STDERR( "line(%d).char(%d):", num, pos-lines->i );
456− sprintf( g_buffer, "line(%d).char(%d):", num, pos-lines->i );
457+ snprintf( g_buffer, CK_ERR_BUF_LENGTH, "line(%d).char(%d):", num, (int)(pos-lines->i) );
457458 lastErrorCat( g_buffer );
458459 }
459460 CK_FPRINTF_STDERR( " " );
@@ -464,7 +465,7 @@ void EM_error( int pos, const char * message, ... ) · 4 unmodified lines
464465 va_end(ap);
465466
466467 va_start(ap, message);
467− vsprintf( g_buffer, message, ap );
468+ vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap );
468469 va_end(ap);
469470
470471 CK_FPRINTF_STDERR( "\n");
@@ -474,7 +475,7 @@ void EM_error( int pos, const char * message, ... ) · 3 unmodified lines
474475
475476
476477 // [%s]:line(%d):
477−void EM_error2( int line, const char * message, ... )
478+void EM_error2( t_CKINT line, const char * message, ... )
478479 {
479480 va_list ap;
480481
@@ -484,12 +485,12 @@ void EM_error2( int line, const char * message, ... ) · 3 unmodified lines
484485 if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" );
485486
486487 CK_FPRINTF_STDERR( "[%s]:", *fileName ? mini(fileName) : "chuck" );
487− sprintf( g_buffer, "[%s]:", *fileName ? mini(fileName) : "chuck" );
488+ snprintf( g_buffer, CK_ERR_BUF_LENGTH, "[%s]:", *fileName ? mini(fileName) : "chuck" );
488489 lastErrorCat( g_buffer );
489490 if(line)
490491 {
491− CK_FPRINTF_STDERR( "line(%d):", line );
492− sprintf( g_buffer, "line(%d):", line );
492+ CK_FPRINTF_STDERR( "line(%d):", (int)line );
493+ snprintf( g_buffer, CK_ERR_BUF_LENGTH, "line(%d):", (int)line );
493494 lastErrorCat( g_buffer );
494495 }
495496 CK_FPRINTF_STDERR( " " );
@@ -500,7 +501,7 @@ void EM_error2( int line, const char * message, ... ) · 4 unmodified lines
500501 va_end( ap );
501502
502503 va_start( ap, message );
503− vsprintf( g_buffer, message, ap );
504+ vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap );
504505 va_end( ap );
505506
506507 lastErrorCat( g_buffer );
@@ -510,7 +511,7 @@ void EM_error2( int line, const char * message, ... ) · 3 unmodified lines
510511
511512
512513 // [%s]:line(%d):
513−void EM_error2b( int line, const char * message, ... )
514+void EM_error2b( t_CKINT line, const char * message, ... )
514515 {
515516 va_list ap;
516517
@@ -520,12 +521,12 @@ void EM_error2b( int line, const char * message, ... ) · 3 unmodified lines
520521 if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" );
521522
522523 CK_FPRINTF_STDERR( "[%s]:", *fileName ? mini(fileName) : "chuck" );
523− sprintf( g_buffer, "[%s]:", *fileName ? mini(fileName) : "chuck" );
524+ snprintf( g_buffer, CK_ERR_BUF_LENGTH, "[%s]:", *fileName ? mini(fileName) : "chuck" );
524525 lastErrorCat( g_buffer );
525526 if(line)
526527 {
527− CK_FPRINTF_STDERR( "line(%d):", line );
528− sprintf( g_buffer, "line(%d):", line );
528+ CK_FPRINTF_STDERR( "line(%d):", (int)line );
529+ snprintf( g_buffer, CK_ERR_BUF_LENGTH, "line(%d):", (int)line );
529530 lastErrorCat( g_buffer );
530531 }
531532 CK_FPRINTF_STDERR( " " );
@@ -536,7 +537,7 @@ void EM_error2b( int line, const char * message, ... ) · 4 unmodified lines
536537 va_end( ap );
537538
538539 va_start( ap, message );
539− vsprintf( g_buffer, message, ap );
540+ vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap );
540541 va_end( ap );
541542
542543 lastErrorCat( g_buffer );
@@ -561,7 +562,7 @@ void EM_error3( const char * message, ... ) · 18 unmodified lines
561562 va_end( ap );
562563
563564 va_start( ap, message );
564− vsprintf( g_buffer, message, ap );
565+ vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap );
565566 va_end( ap );
566567
567568 lastErrorCat( g_buffer );

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t