Showing the changes to src/core/chuck_errmsg.cpp (1 of 37 files). Show all
Unified · Split
| @@ -51,7 +51,8 @@ t_CKBOOL anyErrors= FALSE; · 50 unmodified lines | |||
| 51 | // local global | 51 | // local global |
| 52 | static const char * fileName = ""; | 52 | static const char * fileName = ""; |
| 53 | static int lineNum = 1; | 53 | 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] = ""; | ||
| 55 | static const size_t LASTERROR_SIZE = 1024; | 56 | static const size_t LASTERROR_SIZE = 1024; |
| 56 | static char g_lasterror[LASTERROR_SIZE] = "[chuck]: (no error)"; | 57 | static char g_lasterror[LASTERROR_SIZE] = "[chuck]: (no error)"; |
| 57 | static size_t g_lasterrorIndex = strlen(g_lasterror); | 58 | static size_t g_lasterrorIndex = strlen(g_lasterror); |
| @@ -367,7 +368,7 @@ static const char * g_str[] = { · 309 unmodified lines | |||
| 367 | 368 | ||
| 368 | 369 | ||
| 369 | // intList | 370 | // intList |
| 370 | typedef struct intList {int i; struct intList *rest;} *IntList; | 371 | typedef struct intList {t_CKINT i; struct intList *rest;} *IntList; |
| 371 | static IntList linePos=NULL; | 372 | static IntList linePos=NULL; |
| 372 | 373 | ||
| 373 | 374 | ||
| @@ -387,7 +388,7 @@ static int lastErrorCat(const char * str) · 13 unmodified lines | |||
| 387 | 388 | ||
| 388 | 389 | ||
| 389 | // constructor | 390 | // constructor |
| 390 | static IntList intList( int i, IntList rest ) | 391 | static IntList intList( t_CKINT i, IntList rest ) |
| 391 | { | 392 | { |
| 392 | IntList l = (IntList)checked_malloc(sizeof *l); | 393 | IntList l = (IntList)checked_malloc(sizeof *l); |
| 393 | l->i=i; l->rest=rest; | 394 | l->i=i; l->rest=rest; |
| @@ -431,7 +432,7 @@ void EM_reset_msg() · 37 unmodified lines | |||
| 431 | } | 432 | } |
| 432 | 433 | ||
| 433 | // [%s]:line(%d).char(%d): | 434 | // [%s]:line(%d).char(%d): |
| 434 | void EM_error( int pos, const char * message, ... ) | 435 | void EM_error( t_CKINT pos, const char * message, ... ) |
| 435 | { | 436 | { |
| 436 | va_list ap; | 437 | va_list ap; |
| 437 | IntList lines = linePos; | 438 | IntList lines = linePos; |
| @@ -448,12 +449,12 @@ void EM_error( int pos, const char * message, ... ) · 10 unmodified lines | |||
| 448 | if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" ); | 449 | if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" ); |
| 449 | 450 | ||
| 450 | CK_FPRINTF_STDERR( "[%s]:", *fileName ? mini(fileName) : "chuck" ); | 451 | 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" ); |
| 452 | lastErrorCat( g_buffer ); | 453 | lastErrorCat( g_buffer ); |
| 453 | if(lines) | 454 | if(lines) |
| 454 | { | 455 | { |
| 455 | CK_FPRINTF_STDERR( "line(%d).char(%d):", num, pos-lines->i ); | 456 | 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) ); |
| 457 | lastErrorCat( g_buffer ); | 458 | lastErrorCat( g_buffer ); |
| 458 | } | 459 | } |
| 459 | CK_FPRINTF_STDERR( " " ); | 460 | CK_FPRINTF_STDERR( " " ); |
| @@ -464,7 +465,7 @@ void EM_error( int pos, const char * message, ... ) · 4 unmodified lines | |||
| 464 | va_end(ap); | 465 | va_end(ap); |
| 465 | 466 | ||
| 466 | va_start(ap, message); | 467 | va_start(ap, message); |
| 467 | vsprintf( g_buffer, message, ap ); | 468 | vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap ); |
| 468 | va_end(ap); | 469 | va_end(ap); |
| 469 | 470 | ||
| 470 | CK_FPRINTF_STDERR( "\n"); | 471 | CK_FPRINTF_STDERR( "\n"); |
| @@ -474,7 +475,7 @@ void EM_error( int pos, const char * message, ... ) · 3 unmodified lines | |||
| 474 | 475 | ||
| 475 | 476 | ||
| 476 | // [%s]:line(%d): | 477 | // [%s]:line(%d): |
| 477 | void EM_error2( int line, const char * message, ... ) | 478 | void EM_error2( t_CKINT line, const char * message, ... ) |
| 478 | { | 479 | { |
| 479 | va_list ap; | 480 | va_list ap; |
| 480 | 481 | ||
| @@ -484,12 +485,12 @@ void EM_error2( int line, const char * message, ... ) · 3 unmodified lines | |||
| 484 | if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" ); | 485 | if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" ); |
| 485 | 486 | ||
| 486 | CK_FPRINTF_STDERR( "[%s]:", *fileName ? mini(fileName) : "chuck" ); | 487 | 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" ); |
| 488 | lastErrorCat( g_buffer ); | 489 | lastErrorCat( g_buffer ); |
| 489 | if(line) | 490 | if(line) |
| 490 | { | 491 | { |
| 491 | CK_FPRINTF_STDERR( "line(%d):", line ); | 492 | CK_FPRINTF_STDERR( "line(%d):", (int)line ); |
| 492 | sprintf( g_buffer, "line(%d):", line ); | 493 | snprintf( g_buffer, CK_ERR_BUF_LENGTH, "line(%d):", (int)line ); |
| 493 | lastErrorCat( g_buffer ); | 494 | lastErrorCat( g_buffer ); |
| 494 | } | 495 | } |
| 495 | CK_FPRINTF_STDERR( " " ); | 496 | CK_FPRINTF_STDERR( " " ); |
| @@ -500,7 +501,7 @@ void EM_error2( int line, const char * message, ... ) · 4 unmodified lines | |||
| 500 | va_end( ap ); | 501 | va_end( ap ); |
| 501 | 502 | ||
| 502 | va_start( ap, message ); | 503 | va_start( ap, message ); |
| 503 | vsprintf( g_buffer, message, ap ); | 504 | vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap ); |
| 504 | va_end( ap ); | 505 | va_end( ap ); |
| 505 | 506 | ||
| 506 | lastErrorCat( g_buffer ); | 507 | lastErrorCat( g_buffer ); |
| @@ -510,7 +511,7 @@ void EM_error2( int line, const char * message, ... ) · 3 unmodified lines | |||
| 510 | 511 | ||
| 511 | 512 | ||
| 512 | // [%s]:line(%d): | 513 | // [%s]:line(%d): |
| 513 | void EM_error2b( int line, const char * message, ... ) | 514 | void EM_error2b( t_CKINT line, const char * message, ... ) |
| 514 | { | 515 | { |
| 515 | va_list ap; | 516 | va_list ap; |
| 516 | 517 | ||
| @@ -520,12 +521,12 @@ void EM_error2b( int line, const char * message, ... ) · 3 unmodified lines | |||
| 520 | if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" ); | 521 | if( g_lasterror[0] != '\0' ) lastErrorCat( "\n" ); |
| 521 | 522 | ||
| 522 | CK_FPRINTF_STDERR( "[%s]:", *fileName ? mini(fileName) : "chuck" ); | 523 | 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" ); |
| 524 | lastErrorCat( g_buffer ); | 525 | lastErrorCat( g_buffer ); |
| 525 | if(line) | 526 | if(line) |
| 526 | { | 527 | { |
| 527 | CK_FPRINTF_STDERR( "line(%d):", line ); | 528 | CK_FPRINTF_STDERR( "line(%d):", (int)line ); |
| 528 | sprintf( g_buffer, "line(%d):", line ); | 529 | snprintf( g_buffer, CK_ERR_BUF_LENGTH, "line(%d):", (int)line ); |
| 529 | lastErrorCat( g_buffer ); | 530 | lastErrorCat( g_buffer ); |
| 530 | } | 531 | } |
| 531 | CK_FPRINTF_STDERR( " " ); | 532 | CK_FPRINTF_STDERR( " " ); |
| @@ -536,7 +537,7 @@ void EM_error2b( int line, const char * message, ... ) · 4 unmodified lines | |||
| 536 | va_end( ap ); | 537 | va_end( ap ); |
| 537 | 538 | ||
| 538 | va_start( ap, message ); | 539 | va_start( ap, message ); |
| 539 | vsprintf( g_buffer, message, ap ); | 540 | vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap ); |
| 540 | va_end( ap ); | 541 | va_end( ap ); |
| 541 | 542 | ||
| 542 | lastErrorCat( g_buffer ); | 543 | lastErrorCat( g_buffer ); |
| @@ -561,7 +562,7 @@ void EM_error3( const char * message, ... ) · 18 unmodified lines | |||
| 561 | va_end( ap ); | 562 | va_end( ap ); |
| 562 | 563 | ||
| 563 | va_start( ap, message ); | 564 | va_start( ap, message ); |
| 564 | vsprintf( g_buffer, message, ap ); | 565 | vsnprintf( g_buffer, CK_ERR_BUF_LENGTH, message, ap ); |
| 565 | va_end( ap ); | 566 | va_end( ap ); |
| 566 | 567 | ||
| 567 | lastErrorCat( g_buffer ); | 568 | lastErrorCat( g_buffer ); |