Re: [PATCH] Make git prune remove temporary packs that look like write failures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Tweed wrote:
> On Feb 6, 2008 4:48 PM, Brandon Casey <casey@xxxxxxxxxxxxxxx> wrote:
>> I also suggest taking a look at the functions in builtin-prune-packed.c to see
>> how similar functions are implemented there.
>>
>> Use strlcpy instead of sprintf.
>> Use prefixcmp instead of strncmp.
>> Use same messages as prune_dir() for show_only path and unlink failure.
>> You could also check the opendir call and print a suitable message on failure.
> 
> All the other path creation in builtin-prune.c is using sprintf; is
> doing 3 strlcpy's much better? (I backed off from using snprintf when
> the other element in the if that tested it vanished; I probably ought
> to put that back.)

They use sprintf for the "%02x" part, but they use memcpy to copy the return
of get_object_directory() into a fixed string and then append onto that,
rather than repeatedly writing the same string over and over. Ok, there is one
instance in builtin-prune.c that repeatedly writes path, but builtin-prune-packed.c
does the memcpy thing.

Something like:

	char pathname[PATH_MAX];
	...

	/* check length of dirname not too long */

	memcpy(pathname, dirname, len);

	if (len && pathname[len-1] != '/')
		pathname[len++] = '/';

	...

	while ((de = readdir(dir)...) {
		if (!prefixcmp(...
			if (strlcpy(pathname + len, de->d_name, PATH_MAX - len)
			    >= PATH_MAX - len) {
				warning("too long path encountered: %s%s",
					pathname, de->d_name);
				continue;
			}

			...


-brandon

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux