================ idBitMsg::ReadString ================ */
| 422 | ================ |
| 423 | */ |
| 424 | int idBitMsg::ReadString( char *buffer, int bufferSize ) const { |
| 425 | int l, c; |
| 426 | |
| 427 | ReadByteAlign(); |
| 428 | l = 0; |
| 429 | while( 1 ) { |
| 430 | c = ReadByte(); |
| 431 | if ( c <= 0 || c >= 255 ) { |
| 432 | break; |
| 433 | } |
| 434 | // translate all fmt spec to avoid crash bugs in string routines |
| 435 | if ( c == '%' ) { |
| 436 | c = '.'; |
| 437 | } |
| 438 | |
| 439 | // we will read past any excessively long string, so |
| 440 | // the following data can be read, but the string will |
| 441 | // be truncated |
| 442 | if ( l < bufferSize - 1 ) { |
| 443 | buffer[l] = c; |
| 444 | l++; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | buffer[l] = 0; |
| 449 | return l; |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | ================ |
no test coverage detected