summaryrefslogtreecommitdiffstats
path: root/tools/build/packhex.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>1998-08-20 15:56:57 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>1998-08-20 15:56:57 +0000
commit2394b5abec28643ff386b347c04a3557519e5980 (patch)
treedb9bef609c6c0b04be7f93e395f8113f30381f08 /tools/build/packhex.c
parentdcc240473f29ae26c31c5bb20823820d5a4e39e2 (diff)
downloadrtems-2394b5abec28643ff386b347c04a3557519e5980.tar.bz2
Changed to avoid use of gets().
Diffstat (limited to '')
-rw-r--r--tools/build/packhex.c42
1 files changed, 34 insertions, 8 deletions
diff --git a/tools/build/packhex.c b/tools/build/packhex.c
index 5b19cff12c..3b85a7c927 100644
--- a/tools/build/packhex.c
+++ b/tools/build/packhex.c
@@ -99,7 +99,7 @@ typedef struct /* Functions and constant returning Hex-record vital stats. */
/*--------------------------- function prototypes ----------------------------*/
-Rec_vitals * identify_first_data_record( char * );
+Rec_vitals * identify_first_data_record( char *, int );
Ulong get_ndigit_hex( char *, int );
@@ -420,12 +420,15 @@ int main(
char inbuff[ MAX_LINE_SIZE ], outbuff[ MAX_LINE_SIZE ];
char *in_dptr, *out_dptr;
int d_total, d_count, d_excess, n;
+ int length;
Ulong in_rec_addr, out_rec_addr = 0;
Rec_vitals *rptr;
/* Sift through file until first hex record is identified. */
- if ( ( rptr = identify_first_data_record( inbuff ) ) == NULL )
+
+ rptr = identify_first_data_record( inbuff, MAX_LINE_SIZE );
+ if ( rptr == NULL )
{
fputs( "No hex records found.\n", stderr );
exit( EXIT_FAILURE );
@@ -434,8 +437,7 @@ int main(
/* Attempt data-record splicing until end-of-file is reached. */
d_total = 0;
- do
- {
+ for (;;) {
if ( rptr->is_data_record( inbuff ) == YES )
{ /* Input record is a data record. */
d_count = rptr->get_data_count( inbuff );
@@ -481,7 +483,18 @@ int main(
}
puts( inbuff );
}
- } while ( gets( inbuff ) != NULL );
+
+ inbuff[ MAX_LINE_SIZE - 1 ] = '\0';
+ if ( !fgets( inbuff, MAX_LINE_SIZE, stdin ) )
+ break;
+ if ( inbuff[ MAX_LINE_SIZE - 1 ] ) {
+ fprintf( stderr, "Input line too long" );
+ exit( 1 );
+ }
+ length = strlen(inbuff);
+ inbuff[length - 1] = '\0';
+
+ }
return ( EXIT_SUCCESS );
@@ -503,12 +516,25 @@ int main(
*
*******************************************************************************/
-Rec_vitals * identify_first_data_record( char * buff_ptr )
+Rec_vitals * identify_first_data_record( char * buff_ptr, int max_length )
{
Rec_vitals ** ptr;
+ int length;
+
+
+
+ for ( ;; ) {
+
+ buff_ptr[ max_length - 1 ] = '\0';
+ if ( !fgets( buff_ptr, max_length, stdin ) )
+ break;
+ if ( buff_ptr[ max_length - 1 ] ) {
+ fprintf( stderr, "Input line too long" );
+ exit( 1 );
+ }
+ length = strlen(buff_ptr);
+ buff_ptr[length - 1] = '\0';
- while ( gets( buff_ptr ) != NULL )
- {
for ( ptr = formats ; *ptr != ( Rec_vitals * ) NULL ; ptr++ )
if ( ( *ptr )->is_data_record( buff_ptr ) == YES )
return( *ptr ); /* Successful return. */