@@ -1177,56 +1177,45 @@ static void report_pack_garbage(struct string_list *list)
1177
1177
1178
1178
static void prepare_packed_git_one (char * objdir , int local )
1179
1179
{
1180
- /* Ensure that this buffer is large enough so that we can
1181
- append "/pack/" without clobbering the stack even if
1182
- strlen(objdir) were PATH_MAX. */
1183
- char path [PATH_MAX + 1 + 4 + 1 + 1 ];
1184
- int len ;
1180
+ struct strbuf path = STRBUF_INIT ;
1181
+ size_t dirnamelen ;
1185
1182
DIR * dir ;
1186
1183
struct dirent * de ;
1187
1184
struct string_list garbage = STRING_LIST_INIT_DUP ;
1188
1185
1189
- sprintf ( path , "%s/pack" , objdir );
1190
- len = strlen ( path );
1191
- dir = opendir (path );
1186
+ strbuf_addstr ( & path , objdir );
1187
+ strbuf_addstr ( & path , "/pack" );
1188
+ dir = opendir (path . buf );
1192
1189
if (!dir ) {
1193
1190
if (errno != ENOENT )
1194
1191
error ("unable to open object pack directory: %s: %s" ,
1195
- path , strerror (errno ));
1192
+ path .buf , strerror (errno ));
1193
+ strbuf_release (& path );
1196
1194
return ;
1197
1195
}
1198
- path [len ++ ] = '/' ;
1196
+ strbuf_addch (& path , '/' );
1197
+ dirnamelen = path .len ;
1199
1198
while ((de = readdir (dir )) != NULL ) {
1200
- int namelen = strlen (de -> d_name );
1201
1199
struct packed_git * p ;
1202
1200
1203
- if (len + namelen + 1 > sizeof (path )) {
1204
- if (report_garbage ) {
1205
- struct strbuf sb = STRBUF_INIT ;
1206
- strbuf_addf (& sb , "%.*s/%s" , len - 1 , path , de -> d_name );
1207
- report_garbage ("path too long" , sb .buf );
1208
- strbuf_release (& sb );
1209
- }
1210
- continue ;
1211
- }
1212
-
1213
1201
if (is_dot_or_dotdot (de -> d_name ))
1214
1202
continue ;
1215
1203
1216
- strcpy (path + len , de -> d_name );
1204
+ strbuf_setlen (& path , dirnamelen );
1205
+ strbuf_addstr (& path , de -> d_name );
1217
1206
1218
1207
if (has_extension (de -> d_name , ".idx" )) {
1219
1208
/* Don't reopen a pack we already have. */
1220
1209
for (p = packed_git ; p ; p = p -> next ) {
1221
- if (!memcmp (path , p -> pack_name , len + namelen - 4 ))
1210
+ if (!memcmp (path . buf , p -> pack_name , path . len - 4 ))
1222
1211
break ;
1223
1212
}
1224
1213
if (p == NULL &&
1225
1214
/*
1226
1215
* See if it really is a valid .idx file with
1227
1216
* corresponding .pack file that we can map.
1228
1217
*/
1229
- (p = add_packed_git (path , len + namelen , local )) != NULL )
1218
+ (p = add_packed_git (path . buf , path . len , local )) != NULL )
1230
1219
install_packed_git (p );
1231
1220
}
1232
1221
@@ -1237,13 +1226,14 @@ static void prepare_packed_git_one(char *objdir, int local)
1237
1226
has_extension (de -> d_name , ".pack" ) ||
1238
1227
has_extension (de -> d_name , ".bitmap" ) ||
1239
1228
has_extension (de -> d_name , ".keep" ))
1240
- string_list_append (& garbage , path );
1229
+ string_list_append (& garbage , path . buf );
1241
1230
else
1242
- report_garbage ("garbage found" , path );
1231
+ report_garbage ("garbage found" , path . buf );
1243
1232
}
1244
1233
closedir (dir );
1245
1234
report_pack_garbage (& garbage );
1246
1235
string_list_clear (& garbage , 0 );
1236
+ strbuf_release (& path );
1247
1237
}
1248
1238
1249
1239
static int sort_pack (const void * a_ , const void * b_ )
0 commit comments