@@ -162,18 +162,12 @@ int get_release(char **release, const char *string)
162
162
} else if (n_found > 1 ) {
163
163
// Return multiple releases as a comma-separated string.
164
164
qsort (found , n_found , sizeof (char * ), compar_func );
165
- size_t len = strlen (found [0 ]);
166
- for (int i = 1 ; i < n_found ; i ++ )
167
- len += strlen (found [i ]) + strlen (tag_separator );
168
- char * new_retval = realloc (retval , len + strlen (tag_separator ));
169
- if (new_retval == NULL )
170
- exit (EXIT_FAILURE );
171
- retval = new_retval ;
172
- retval [0 ] = '\0' ;
173
- strcpy (retval , found [0 ]);
165
+ if (retval == NULL )
166
+ retval = calloc (MAX_TAG_LEN , 1 );
167
+ strncpy (retval , found [0 ], MAX_TAG_LEN );
174
168
for (int i = 1 ; i < n_found ; i ++ ) {
175
- strcat (retval , tag_separator );
176
- strcat (retval , found [i ]);
169
+ strncat (retval , tag_separator , MAX_TAG_LEN - strlen ( retval ) );
170
+ strncat (retval , found [i ], MAX_TAG_LEN - strlen ( retval ) );
177
171
}
178
172
* release = retval ;
179
173
}
@@ -245,14 +239,15 @@ void replace_commas_in_tag(char *tag, const char *string)
245
239
size_t taglen = strlen (tag ); // Initial length
246
240
size_t stringlen = strlen (string );
247
241
248
- for (size_t i = 0 ; i < taglen ; i ++ ) {
242
+ for (size_t i = 0 ; i < strlen ( tag ) ; i ++ ) {
249
243
if (tag [i ] == ',' ) {
250
244
// Only do it if there's enough space left in the tag buffer.
251
- if (strlen (tag ) + stringlen + 1 >= MAX_TAG_LEN )
245
+ if (strlen (tag ) + stringlen - 1 >= MAX_TAG_LEN )
252
246
return ;
253
247
254
- memmove (tag + i + stringlen , tag + i + 1 , strlen (tag + i + 1 ));
248
+ memmove (tag + i + stringlen , tag + i + 1 , strlen (tag + i ));
255
249
memcpy (tag + i , string , stringlen );
250
+ i += stringlen ;
256
251
}
257
252
}
258
253
}
0 commit comments