@@ -678,27 +678,29 @@ stab_int_type (void *p, unsigned int size, bool unsignedp)
678678
679679 cache [size - 1 ] = tindex ;
680680
681- sprintf (buf , "%ld=r%ld;" , tindex , tindex );
681+ int len = sprintf (buf , "%ld=r%ld;" , tindex , tindex );
682682 if (unsignedp )
683683 {
684- strcat (buf , "0;" );
684+ strcpy (buf + len , "0;" );
685+ len += 2 ;
685686 if (size < sizeof (long ))
686- sprintf (buf + strlen ( buf ) , "%ld;" , ((long ) 1 << (size * 8 )) - 1 );
687+ sprintf (buf + len , "%ld;" , ((long ) 1 << (size * 8 )) - 1 );
687688 else if (size == sizeof (long ))
688- strcat (buf , "-1;" );
689+ strcpy (buf + len , "-1;" );
689690 else if (size == 8 )
690- strcat (buf , "01777777777777777777777;" );
691+ strcpy (buf + len , "01777777777777777777777;" );
691692 else
692693 abort ();
693694 }
694695 else
695696 {
696697 if (size <= sizeof (long ))
697- sprintf (buf + strlen ( buf ) , "%ld;%ld;" ,
698+ sprintf (buf + len , "%ld;%ld;" ,
698699 (long ) - ((unsigned long ) 1 << (size * 8 - 1 )),
699700 (long ) (((unsigned long ) 1 << (size * 8 - 1 )) - 1 ));
700701 else if (size == 8 )
701- strcat (buf , "01000000000000000000000;0777777777777777777777;" );
702+ strcpy (buf + len ,
703+ "01000000000000000000000;0777777777777777777777;" );
702704 else
703705 abort ();
704706 }
@@ -828,19 +830,19 @@ stab_enum_type (void *p, const char *tag, const char **names,
828830 len += strlen (* pn ) + 22 ;
829831
830832 buf = xmalloc (len );
831-
833+ char * out = buf ;
832834 if (tag == NULL )
833- strcpy ( buf , "e" );
835+ out = stpcpy ( out , "e" );
834836 else
835837 {
836838 tindex = info -> type_index ;
837839 ++ info -> type_index ;
838- sprintf (buf , "%s:T%ld=e" , tag , tindex );
840+ out += sprintf (out , "%s:T%ld=e" , tag , tindex );
839841 }
840842
841843 for (pn = names , pv = vals ; * pn != NULL ; pn ++ , pv ++ )
842- sprintf ( buf + strlen ( buf ) , "%s:%ld," , * pn , (long ) * pv );
843- strcat ( buf , ";" );
844+ out += sprintf ( out , "%s:%ld," , * pn , (long ) * pv );
845+ strcpy ( out , ";" );
844846
845847 if (tag == NULL )
846848 {
@@ -1031,23 +1033,20 @@ stab_array_type (void *p, bfd_signed_vma low, bfd_signed_vma high,
10311033 element = stab_pop_type (info );
10321034
10331035 buf = xmalloc (strlen (range ) + strlen (element ) + 70 );
1034-
1036+ char * out = buf ;
10351037 if (! stringp )
1036- {
1037- tindex = 0 ;
1038- * buf = '\0' ;
1039- }
1038+ tindex = 0 ;
10401039 else
10411040 {
10421041 /* We need to define a type in order to include the string
10431042 attribute. */
10441043 tindex = info -> type_index ;
10451044 ++ info -> type_index ;
10461045 definition = true;
1047- sprintf (buf , "%ld=@S;" , tindex );
1046+ out += sprintf (out , "%ld=@S;" , tindex );
10481047 }
10491048
1050- sprintf (buf + strlen ( buf ) , "ar%s;%ld;%ld;%s" ,
1049+ sprintf (out , "ar%s;%ld;%ld;%s" ,
10511050 range , (long ) low , (long ) high , element );
10521051 free (range );
10531052 free (element );
@@ -1073,23 +1072,20 @@ stab_set_type (void *p, bool bitstringp)
10731072
10741073 s = stab_pop_type (info );
10751074 buf = xmalloc (strlen (s ) + 26 );
1076-
1075+ char * out = buf ;
10771076 if (! bitstringp )
1078- {
1079- * buf = '\0' ;
1080- tindex = 0 ;
1081- }
1077+ tindex = 0 ;
10821078 else
10831079 {
10841080 /* We need to define a type in order to include the string
10851081 attribute. */
10861082 tindex = info -> type_index ;
10871083 ++ info -> type_index ;
10881084 definition = true;
1089- sprintf (buf , "%ld=@S;" , tindex );
1085+ out += sprintf (out , "%ld=@S;" , tindex );
10901086 }
10911087
1092- sprintf (buf + strlen ( buf ) , "S%s" , s );
1088+ sprintf (out , "S%s" , s );
10931089 free (s );
10941090
10951091 return stab_push_string (info , buf , tindex , definition , 0 );
@@ -1304,11 +1300,11 @@ stab_start_struct_type (void *p, const char *tag, unsigned int id,
13041300 long tindex ;
13051301 bool definition ;
13061302 char buf [40 ];
1303+ char * out = buf ;
13071304
13081305 if (id == 0 )
13091306 {
13101307 tindex = 0 ;
1311- * buf = '\0' ;
13121308 definition = false;
13131309 }
13141310 else
@@ -1317,11 +1313,11 @@ stab_start_struct_type (void *p, const char *tag, unsigned int id,
13171313 & size );
13181314 if (tindex < 0 )
13191315 return false;
1320- sprintf (buf , "%ld=" , tindex );
1316+ out += sprintf (out , "%ld=" , tindex );
13211317 definition = true;
13221318 }
13231319
1324- sprintf (buf + strlen ( buf ) , "%c%u" ,
1320+ sprintf (out , "%c%u" ,
13251321 structp ? 's' : 'u' ,
13261322 size );
13271323
@@ -1699,19 +1695,21 @@ stab_class_method_var (struct stab_write_handle *info, const char *physname,
16991695 else
17001696 typec = '*' ;
17011697
1698+ size_t cur_len = strlen (info -> type_stack -> methods );
17021699 info -> type_stack -> methods =
1703- xrealloc (info -> type_stack -> methods ,
1704- (strlen (info -> type_stack -> methods ) + strlen (type )
1705- + strlen (physname ) + (contextp ? strlen (context ) : 0 ) + 40 ));
1706-
1707- sprintf (info -> type_stack -> methods + strlen (info -> type_stack -> methods ),
1708- "%s:%s;%c%c%c" , type , physname , visc , qualc , typec );
1700+ xrealloc (info -> type_stack -> methods , (cur_len
1701+ + strlen (type )
1702+ + strlen (physname )
1703+ + (contextp ? strlen (context ) : 0 )
1704+ + 40 ));
1705+
1706+ char * out = info -> type_stack -> methods + cur_len ;
1707+ out += sprintf (out , "%s:%s;%c%c%c" , type , physname , visc , qualc , typec );
17091708 free (type );
17101709
17111710 if (contextp )
17121711 {
1713- sprintf (info -> type_stack -> methods + strlen (info -> type_stack -> methods ),
1714- "%ld;%s;" , (long ) voffset , context );
1712+ sprintf (out , "%ld;%s;" , (long ) voffset , context );
17151713 free (context );
17161714 }
17171715
@@ -1800,36 +1798,36 @@ stab_end_class_type (void *p)
18001798
18011799 buf = xmalloc (len );
18021800
1803- strcpy (buf , info -> type_stack -> string );
1801+ char * out = stpcpy (buf , info -> type_stack -> string );
18041802
18051803 if (info -> type_stack -> baseclasses != NULL )
18061804 {
1807- sprintf ( buf + strlen ( buf ) , "!%u," , i );
1805+ out += sprintf ( out , "!%u," , i );
18081806 for (i = 0 ; info -> type_stack -> baseclasses [i ] != NULL ; i ++ )
18091807 {
1810- strcat ( buf , info -> type_stack -> baseclasses [i ]);
1808+ out = stpcpy ( out , info -> type_stack -> baseclasses [i ]);
18111809 free (info -> type_stack -> baseclasses [i ]);
18121810 }
18131811 free (info -> type_stack -> baseclasses );
18141812 info -> type_stack -> baseclasses = NULL ;
18151813 }
18161814
1817- strcat ( buf , info -> type_stack -> fields );
1815+ out = stpcpy ( out , info -> type_stack -> fields );
18181816 free (info -> type_stack -> fields );
18191817 info -> type_stack -> fields = NULL ;
18201818
18211819 if (info -> type_stack -> methods != NULL )
18221820 {
1823- strcat ( buf , info -> type_stack -> methods );
1821+ out = stpcpy ( out , info -> type_stack -> methods );
18241822 free (info -> type_stack -> methods );
18251823 info -> type_stack -> methods = NULL ;
18261824 }
18271825
1828- strcat ( buf , ";" );
1826+ out = stpcpy ( out , ";" );
18291827
18301828 if (info -> type_stack -> vtable != NULL )
18311829 {
1832- strcat ( buf , info -> type_stack -> vtable );
1830+ out = stpcpy ( out , info -> type_stack -> vtable );
18331831 free (info -> type_stack -> vtable );
18341832 info -> type_stack -> vtable = NULL ;
18351833 }
0 commit comments