Changeset 2394b5a in rtems


Ignore:
Timestamp:
08/20/98 15:56:57 (25 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, 4.8, 4.9, 5, master
Children:
7c16a331
Parents:
dcc2404
Message:

Changed to avoid use of gets().

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • c/build-tools/packhex.c

    rdcc2404 r2394b5a  
    100100/*--------------------------- function prototypes ----------------------------*/
    101101
    102 Rec_vitals  * identify_first_data_record( char * );
     102Rec_vitals  * identify_first_data_record( char *, int );
    103103Ulong         get_ndigit_hex( char *, int );
    104104
     
    421421    char       *in_dptr, *out_dptr;
    422422    int        d_total, d_count, d_excess, n;
     423    int        length;
    423424    Ulong      in_rec_addr, out_rec_addr = 0;
    424425    Rec_vitals *rptr;
     
    426427
    427428    /* Sift through file until first hex record is identified.    */
    428     if ( ( rptr = identify_first_data_record( inbuff ) ) == NULL )
     429
     430    rptr = identify_first_data_record( inbuff, MAX_LINE_SIZE );
     431    if ( rptr == NULL )
    429432    {
    430433        fputs( "No hex records found.\n", stderr );
     
    435438    /* Attempt data-record splicing until end-of-file is reached. */
    436439    d_total = 0;
    437     do
    438     {
     440    for (;;) {
    439441        if ( rptr->is_data_record( inbuff ) == YES )
    440442        { /* Input record is a data record. */
     
    482484            puts( inbuff );
    483485        }
    484     } while ( gets( inbuff ) != NULL );
     486
     487        inbuff[ MAX_LINE_SIZE - 1 ] = '\0';
     488        if ( !fgets( inbuff, MAX_LINE_SIZE, stdin ) )
     489           break;
     490        if ( inbuff[ MAX_LINE_SIZE - 1 ] ) {
     491           fprintf( stderr, "Input line too long" );
     492           exit( 1 );
     493        }
     494        length = strlen(inbuff);
     495        inbuff[length - 1] = '\0';
     496       
     497    }
    485498
    486499
     
    504517*******************************************************************************/
    505518
    506 Rec_vitals * identify_first_data_record( char * buff_ptr )
     519Rec_vitals * identify_first_data_record( char * buff_ptr, int max_length )
    507520{
    508521    Rec_vitals  ** ptr;
    509 
    510     while ( gets( buff_ptr ) != NULL )
    511     {
     522    int            length;
     523
     524
     525
     526    for ( ;; ) {
     527
     528        buff_ptr[ max_length - 1 ] = '\0';
     529        if ( !fgets( buff_ptr, max_length, stdin ) )
     530           break;
     531        if ( buff_ptr[ max_length - 1 ] ) {
     532           fprintf( stderr, "Input line too long" );
     533           exit( 1 );
     534        }
     535        length = strlen(buff_ptr);
     536        buff_ptr[length - 1] = '\0';
     537
    512538        for ( ptr = formats ; *ptr != ( Rec_vitals * ) NULL ; ptr++ )
    513539            if ( ( *ptr )->is_data_record( buff_ptr ) == YES )
  • c/build-tools/src/packhex.c

    rdcc2404 r2394b5a  
    100100/*--------------------------- function prototypes ----------------------------*/
    101101
    102 Rec_vitals  * identify_first_data_record( char * );
     102Rec_vitals  * identify_first_data_record( char *, int );
    103103Ulong         get_ndigit_hex( char *, int );
    104104
     
    421421    char       *in_dptr, *out_dptr;
    422422    int        d_total, d_count, d_excess, n;
     423    int        length;
    423424    Ulong      in_rec_addr, out_rec_addr = 0;
    424425    Rec_vitals *rptr;
     
    426427
    427428    /* Sift through file until first hex record is identified.    */
    428     if ( ( rptr = identify_first_data_record( inbuff ) ) == NULL )
     429
     430    rptr = identify_first_data_record( inbuff, MAX_LINE_SIZE );
     431    if ( rptr == NULL )
    429432    {
    430433        fputs( "No hex records found.\n", stderr );
     
    435438    /* Attempt data-record splicing until end-of-file is reached. */
    436439    d_total = 0;
    437     do
    438     {
     440    for (;;) {
    439441        if ( rptr->is_data_record( inbuff ) == YES )
    440442        { /* Input record is a data record. */
     
    482484            puts( inbuff );
    483485        }
    484     } while ( gets( inbuff ) != NULL );
     486
     487        inbuff[ MAX_LINE_SIZE - 1 ] = '\0';
     488        if ( !fgets( inbuff, MAX_LINE_SIZE, stdin ) )
     489           break;
     490        if ( inbuff[ MAX_LINE_SIZE - 1 ] ) {
     491           fprintf( stderr, "Input line too long" );
     492           exit( 1 );
     493        }
     494        length = strlen(inbuff);
     495        inbuff[length - 1] = '\0';
     496       
     497    }
    485498
    486499
     
    504517*******************************************************************************/
    505518
    506 Rec_vitals * identify_first_data_record( char * buff_ptr )
     519Rec_vitals * identify_first_data_record( char * buff_ptr, int max_length )
    507520{
    508521    Rec_vitals  ** ptr;
    509 
    510     while ( gets( buff_ptr ) != NULL )
    511     {
     522    int            length;
     523
     524
     525
     526    for ( ;; ) {
     527
     528        buff_ptr[ max_length - 1 ] = '\0';
     529        if ( !fgets( buff_ptr, max_length, stdin ) )
     530           break;
     531        if ( buff_ptr[ max_length - 1 ] ) {
     532           fprintf( stderr, "Input line too long" );
     533           exit( 1 );
     534        }
     535        length = strlen(buff_ptr);
     536        buff_ptr[length - 1] = '\0';
     537
    512538        for ( ptr = formats ; *ptr != ( Rec_vitals * ) NULL ; ptr++ )
    513539            if ( ( *ptr )->is_data_record( buff_ptr ) == YES )
  • tools/build/packhex.c

    rdcc2404 r2394b5a  
    100100/*--------------------------- function prototypes ----------------------------*/
    101101
    102 Rec_vitals  * identify_first_data_record( char * );
     102Rec_vitals  * identify_first_data_record( char *, int );
    103103Ulong         get_ndigit_hex( char *, int );
    104104
     
    421421    char       *in_dptr, *out_dptr;
    422422    int        d_total, d_count, d_excess, n;
     423    int        length;
    423424    Ulong      in_rec_addr, out_rec_addr = 0;
    424425    Rec_vitals *rptr;
     
    426427
    427428    /* Sift through file until first hex record is identified.    */
    428     if ( ( rptr = identify_first_data_record( inbuff ) ) == NULL )
     429
     430    rptr = identify_first_data_record( inbuff, MAX_LINE_SIZE );
     431    if ( rptr == NULL )
    429432    {
    430433        fputs( "No hex records found.\n", stderr );
     
    435438    /* Attempt data-record splicing until end-of-file is reached. */
    436439    d_total = 0;
    437     do
    438     {
     440    for (;;) {
    439441        if ( rptr->is_data_record( inbuff ) == YES )
    440442        { /* Input record is a data record. */
     
    482484            puts( inbuff );
    483485        }
    484     } while ( gets( inbuff ) != NULL );
     486
     487        inbuff[ MAX_LINE_SIZE - 1 ] = '\0';
     488        if ( !fgets( inbuff, MAX_LINE_SIZE, stdin ) )
     489           break;
     490        if ( inbuff[ MAX_LINE_SIZE - 1 ] ) {
     491           fprintf( stderr, "Input line too long" );
     492           exit( 1 );
     493        }
     494        length = strlen(inbuff);
     495        inbuff[length - 1] = '\0';
     496       
     497    }
    485498
    486499
     
    504517*******************************************************************************/
    505518
    506 Rec_vitals * identify_first_data_record( char * buff_ptr )
     519Rec_vitals * identify_first_data_record( char * buff_ptr, int max_length )
    507520{
    508521    Rec_vitals  ** ptr;
    509 
    510     while ( gets( buff_ptr ) != NULL )
    511     {
     522    int            length;
     523
     524
     525
     526    for ( ;; ) {
     527
     528        buff_ptr[ max_length - 1 ] = '\0';
     529        if ( !fgets( buff_ptr, max_length, stdin ) )
     530           break;
     531        if ( buff_ptr[ max_length - 1 ] ) {
     532           fprintf( stderr, "Input line too long" );
     533           exit( 1 );
     534        }
     535        length = strlen(buff_ptr);
     536        buff_ptr[length - 1] = '\0';
     537
    512538        for ( ptr = formats ; *ptr != ( Rec_vitals * ) NULL ; ptr++ )
    513539            if ( ( *ptr )->is_data_record( buff_ptr ) == YES )
  • tools/build/src/packhex.c

    rdcc2404 r2394b5a  
    100100/*--------------------------- function prototypes ----------------------------*/
    101101
    102 Rec_vitals  * identify_first_data_record( char * );
     102Rec_vitals  * identify_first_data_record( char *, int );
    103103Ulong         get_ndigit_hex( char *, int );
    104104
     
    421421    char       *in_dptr, *out_dptr;
    422422    int        d_total, d_count, d_excess, n;
     423    int        length;
    423424    Ulong      in_rec_addr, out_rec_addr = 0;
    424425    Rec_vitals *rptr;
     
    426427
    427428    /* Sift through file until first hex record is identified.    */
    428     if ( ( rptr = identify_first_data_record( inbuff ) ) == NULL )
     429
     430    rptr = identify_first_data_record( inbuff, MAX_LINE_SIZE );
     431    if ( rptr == NULL )
    429432    {
    430433        fputs( "No hex records found.\n", stderr );
     
    435438    /* Attempt data-record splicing until end-of-file is reached. */
    436439    d_total = 0;
    437     do
    438     {
     440    for (;;) {
    439441        if ( rptr->is_data_record( inbuff ) == YES )
    440442        { /* Input record is a data record. */
     
    482484            puts( inbuff );
    483485        }
    484     } while ( gets( inbuff ) != NULL );
     486
     487        inbuff[ MAX_LINE_SIZE - 1 ] = '\0';
     488        if ( !fgets( inbuff, MAX_LINE_SIZE, stdin ) )
     489           break;
     490        if ( inbuff[ MAX_LINE_SIZE - 1 ] ) {
     491           fprintf( stderr, "Input line too long" );
     492           exit( 1 );
     493        }
     494        length = strlen(inbuff);
     495        inbuff[length - 1] = '\0';
     496       
     497    }
    485498
    486499
     
    504517*******************************************************************************/
    505518
    506 Rec_vitals * identify_first_data_record( char * buff_ptr )
     519Rec_vitals * identify_first_data_record( char * buff_ptr, int max_length )
    507520{
    508521    Rec_vitals  ** ptr;
    509 
    510     while ( gets( buff_ptr ) != NULL )
    511     {
     522    int            length;
     523
     524
     525
     526    for ( ;; ) {
     527
     528        buff_ptr[ max_length - 1 ] = '\0';
     529        if ( !fgets( buff_ptr, max_length, stdin ) )
     530           break;
     531        if ( buff_ptr[ max_length - 1 ] ) {
     532           fprintf( stderr, "Input line too long" );
     533           exit( 1 );
     534        }
     535        length = strlen(buff_ptr);
     536        buff_ptr[length - 1] = '\0';
     537
    512538        for ( ptr = formats ; *ptr != ( Rec_vitals * ) NULL ; ptr++ )
    513539            if ( ( *ptr )->is_data_record( buff_ptr ) == YES )
Note: See TracChangeset for help on using the changeset viewer.