GNU bug report logs -
#11761
Slight bug in split :-)
Previous Next
Reported by: Jim Meyering <jim <at> meyering.net>
Date: Thu, 21 Jun 2012 22:16:02 UTC
Severity: normal
Done: Pádraig Brady <P <at> draigBrady.com>
Bug is archived. No further changes may be made.
Full log
Message #18 received at 11761-done <at> debbugs.gnu.org (full text, mbox):
On 06/22/2012 10:26 AM, Jim Meyering wrote:
> Pádraig Brady wrote:
>> I'll push the attached in a while.
> ...
>> @@ -360,10 +363,25 @@ create (const char *name)
>> {
>> if (!filter_command)
>> {
>> + int fd;
>> + struct stat out_stat_buf;
>> +
>> if (verbose)
>> fprintf (stdout, _("creating file %s\n"), quote (name));
>> - return open (name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
>> - (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
>> +
>> + fd = open (name, O_WRONLY | O_CREAT | O_BINARY,
>> + (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH));
>> + if (fd < 0)
>> + return fd;
>> + if (fstat (fd, &out_stat_buf) != 0)
>> + error (EXIT_FAILURE, errno, _("failed to stat %s"), quote (name));
>> + if (SAME_INODE (in_stat_buf, out_stat_buf))
>> + error (EXIT_FAILURE, 0, _("%s would overwrite input; aborting"),
>> + quote (name));
>> + if (ftruncate (fd, 0) != 0)
>> + error (EXIT_FAILURE, errno, _("%s: error truncating"), quote (name));
>> +
>> + return fd;
>
> Thanks.
> That looks fine and passes "make check syntax-check" (no surprise).
> Please move the declaration of "fd" down to the point of initialization.
OK I'll move the stat declaration down too.
> That would induce a line-split, but perhaps this is a good excuse to
> factor out these: (maybe name it something like MODE_RW_UGO)
>
> $ git grep -l 'S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH'
> src/dd.c
> src/mkfifo.c
> src/mknod.c
> src/split.c
> src/touch.c
> src/truncate.c
OK I'll do that first.
cheers,
Pádraig.
This bug report was last modified 13 years and 22 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.