Debian Bug report logs - #848231
bugs in scandir example program

version graph

Package: manpages-dev; Maintainer for manpages-dev is Dr. Tobias Quathamer <toddy@debian.org>; Source for manpages-dev is src:manpages (PTS, buildd, popcon).

Reported by: Ian Jackson <ijackson@chiark.greenend.org.uk>

Date: Thu, 15 Dec 2016 12:57:02 UTC

Severity: minor

Tags: fixed-upstream

Found in version manpages/3.74-1

Reply or subscribe to this bug.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#848231; Package manpages-dev. (Thu, 15 Dec 2016 12:57:05 GMT) (full text, mbox, link).


Acknowledgement sent to Ian Jackson <ijackson@chiark.greenend.org.uk>:
New Bug report received and forwarded. Copy sent to Martin Schulze <joey@debian.org>. (Thu, 15 Dec 2016 12:57:05 GMT) (full text, mbox, link).


Message #5 received at submit@bugs.debian.org (full text, mbox, reply):

From: Ian Jackson <ijackson@chiark.greenend.org.uk>
To: submit@bugs.debian.org
Subject: bugs in scandir example program
Date: Thu, 15 Dec 2016 12:55:54 +0000
Package: manpages-dev
Version: 3.74-1
Severity: minor

I cut and pasted the example program from scandir(3) and found that it
had some bugs which caused compiler warnings with -Wall.  Here is a
patch (to the example program, not to the nroff) to fix them.

Thanks,
Ian.

--- t.c.orig	2016-12-15 12:52:33.181859142 +0000
+++ t.c	2016-12-15 12:55:08.939521298 +0000
@@ -1,6 +1,8 @@
        #define _SVID_SOURCE
        /* print files in current directory in reverse order */
        #include <dirent.h>
+       #include <stdio.h>
+       #include <stdlib.h>
 
        int
        main(void)
@@ -18,4 +20,5 @@
                }
                free(namelist);
            }
+           return 0;
        }


-- 
Ian Jackson <ijackson@chiark.greenend.org.uk>   These opinions are my own.

If I emailed you from an address @fyvzl.net or @evade.org.uk, that is
a private address which bypasses my fierce spamfilter.



Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#848231; Package manpages-dev. (Thu, 15 Dec 2016 13:33:10 GMT) (full text, mbox, link).


Acknowledgement sent to mtk.manpages@gmail.com:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Thu, 15 Dec 2016 13:33:10 GMT) (full text, mbox, link).


Message #10 received at 848231@bugs.debian.org (full text, mbox, reply):

From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Ian Jackson <ijackson@chiark.greenend.org.uk>, 848231@bugs.debian.org
Cc: control@bugs.debian.org
Subject: Re: Bug#848231: bugs in scandir example program
Date: Thu, 15 Dec 2016 14:31:28 +0100
tags 848231 fixed-upstream
thanks

On 15 December 2016 at 13:55, Ian Jackson
<ijackson@chiark.greenend.org.uk> wrote:
> Package: manpages-dev
> Version: 3.74-1
> Severity: minor
>
> I cut and pasted the example program from scandir(3) and found that it
> had some bugs which caused compiler warnings with -Wall.  Here is a
> patch (to the example program, not to the nroff) to fix them.
>
> Thanks,
> Ian.
>
> --- t.c.orig    2016-12-15 12:52:33.181859142 +0000
> +++ t.c 2016-12-15 12:55:08.939521298 +0000
> @@ -1,6 +1,8 @@
>         #define _SVID_SOURCE
>         /* print files in current directory in reverse order */
>         #include <dirent.h>
> +       #include <stdio.h>
> +       #include <stdlib.h>
>
>         int
>         main(void)
> @@ -18,4 +20,5 @@
>                 }
>                 free(namelist);
>             }
> +           return 0;
>         }
>

Thanks, Ian. Fixed pretty much as you suggest. The program doesn't
even compile as it was given! Looks like I injected the error after a
user report 4 years ago (changed "0" to "NULL").

Cheers,

Michael


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/



Added tag(s) fixed-upstream. Request was from "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com> to control@bugs.debian.org. (Thu, 15 Dec 2016 13:33:11 GMT) (full text, mbox, link).


Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#848231; Package manpages-dev. (Thu, 15 Dec 2016 14:00:02 GMT) (full text, mbox, link).


Acknowledgement sent to Ian Jackson <ijackson@chiark.greenend.org.uk>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Thu, 15 Dec 2016 14:00:03 GMT) (full text, mbox, link).


Message #17 received at 848231@bugs.debian.org (full text, mbox, reply):

From: Ian Jackson <ijackson@chiark.greenend.org.uk>
To: mtk.manpages@gmail.com
Cc: 848231@bugs.debian.org
Subject: Re: Bug#848231: bugs in scandir example program
Date: Thu, 15 Dec 2016 13:56:26 +0000
Michael Kerrisk (man-pages) writes ("Re: Bug#848231: bugs in scandir example program"):
> tags 848231 fixed-upstream
> thanks
...> 
> On 15 December 2016 at 13:55, Ian Jackson
> >         int
> >         main(void)
> > @@ -18,4 +20,5 @@
> >                 }
> >                 free(namelist);
> >             }
> > +           return 0;
> >         }
> >
> 
> Thanks, Ian. Fixed pretty much as you suggest. The program doesn't
> even compile as it was given! Looks like I injected the error after a
> user report 4 years ago (changed "0" to "NULL").

Thanks.  But, 0 should be 0, not NULL.

NULL is a null pointer constant but main returns int.

(Even if main returned a pointer, 0 would be legal, because 0 is a
valid nll pointer constant, but I guess for pedagogic reasons using
NULL is probaby better in manpages where pointers are meant.)

Ian.

-- 
Ian Jackson <ijackson@chiark.greenend.org.uk>   These opinions are my own.

If I emailed you from an address @fyvzl.net or @evade.org.uk, that is
a private address which bypasses my fierce spamfilter.



Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#848231; Package manpages-dev. (Thu, 15 Dec 2016 16:03:02 GMT) (full text, mbox, link).


Acknowledgement sent to mtk.manpages@gmail.com:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Thu, 15 Dec 2016 16:03:02 GMT) (full text, mbox, link).


Message #22 received at 848231@bugs.debian.org (full text, mbox, reply):

From: "Michael Kerrisk (man-pages)" <mtk.manpages@gmail.com>
To: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cc: 848231@bugs.debian.org
Subject: Re: Bug#848231: bugs in scandir example program
Date: Thu, 15 Dec 2016 16:59:38 +0100
On 15 December 2016 at 14:56, Ian Jackson
<ijackson@chiark.greenend.org.uk> wrote:
> Michael Kerrisk (man-pages) writes ("Re: Bug#848231: bugs in scandir example program"):
>> tags 848231 fixed-upstream
>> thanks
> ...>
>> On 15 December 2016 at 13:55, Ian Jackson
>> >         int
>> >         main(void)
>> > @@ -18,4 +20,5 @@
>> >                 }
>> >                 free(namelist);
>> >             }
>> > +           return 0;
>> >         }
>> >
>>
>> Thanks, Ian. Fixed pretty much as you suggest. The program doesn't
>> even compile as it was given! Looks like I injected the error after a
>> user report 4 years ago (changed "0" to "NULL").
>
> Thanks.  But, 0 should be 0, not NULL.
>
> NULL is a null pointer constant but main returns int.
>
> (Even if main returned a pointer, 0 would be legal, because 0 is a
> valid nll pointer constant, but I guess for pedagogic reasons using
> NULL is probaby better in manpages where pointers are meant.)

We've misunderstood each other. Here's how I think i is:

1. You sent me a patch against a reasonably old version of the program
(pre 2012 upstream).

2. In 2012, I made this change in the code:

-           n = scandir(".", &namelist, 0, alphasort);
+           n = scandir(".", &namelist, NULL, alphasort);

3. In that preceding change, I did not add a #include for <stdio.h>,
so the code would not even compile.

All fixed now. This is the current code:

       #define _DEFAULT_SOURCE
       #include <dirent.h>
       #include <stdio.h>
       #include <stdlib.h>

       int
       main(void)
       {
           struct dirent **namelist;
           int n;

           n = scandir(".", &namelist, NULL, alphasort);
           if (n == -1) {
               perror("scandir");
               exit(EXIT_FAILURE);
           }

           while (n--) {
               printf("%s\n", namelist[n]->d_name);
               free(namelist[n]);
           }
           free(namelist);

           exit(EXIT_SUCCESS);
       }

Cheers,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/


-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/



Information forwarded to debian-bugs-dist@lists.debian.org, Martin Schulze <joey@debian.org>:
Bug#848231; Package manpages-dev. (Thu, 15 Dec 2016 16:09:02 GMT) (full text, mbox, link).


Acknowledgement sent to Ian Jackson <ijackson@chiark.greenend.org.uk>:
Extra info received and forwarded to list. Copy sent to Martin Schulze <joey@debian.org>. (Thu, 15 Dec 2016 16:09:02 GMT) (full text, mbox, link).


Message #27 received at 848231@bugs.debian.org (full text, mbox, reply):

From: Ian Jackson <ijackson@chiark.greenend.org.uk>
To: mtk.manpages@gmail.com
Cc: 848231@bugs.debian.org
Subject: Re: Bug#848231: bugs in scandir example program
Date: Thu, 15 Dec 2016 16:08:08 +0000
Michael Kerrisk (man-pages) writes ("Re: Bug#848231: bugs in scandir example program"):
> We've misunderstood each other. Here's how I think i is:
> 
> 1. You sent me a patch against a reasonably old version of the program
> (pre 2012 upstream).
> 
> 2. In 2012, I made this change in the code:
> 
> -           n = scandir(".", &namelist, 0, alphasort);
> +           n = scandir(".", &namelist, NULL, alphasort);

Oh, right.  Jolly good.

Thanks,
Ian.

-- 
Ian Jackson <ijackson@chiark.greenend.org.uk>   These opinions are my own.

If I emailed you from an address @fyvzl.net or @evade.org.uk, that is
a private address which bypasses my fierce spamfilter.



Information forwarded to debian-bugs-dist@lists.debian.org, Dr. Tobias Quathamer <toddy@debian.org>:
Bug#848231; Package manpages-dev. (Wed, 26 Jan 2022 19:03:04 GMT) (full text, mbox, link).


Acknowledgement sent to Florian Ernst <florian_ernst@gmx.net>:
Extra info received and forwarded to list. Copy sent to Dr. Tobias Quathamer <toddy@debian.org>. (Wed, 26 Jan 2022 19:03:04 GMT) (full text, mbox, link).


Message #32 received at 848231@bugs.debian.org (full text, mbox, reply):

From: Florian Ernst <florian_ernst@gmx.net>
To: 848231@bugs.debian.org
Subject: Re: Bug#848231: bugs in scandir example program
Date: Wed, 26 Jan 2022 20:02:22 +0100
[Message part 1 (text/plain, inline)]
On Thu, Dec 15, 2016 at 04:59:38PM +0100, Michael Kerrisk (man-pages) wrote:
> [...]
> All fixed now. This is the current code:
> 
>        #define _DEFAULT_SOURCE
>        #include <dirent.h>
>        #include <stdio.h>
>        #include <stdlib.h>
> 
>        int
>        main(void)
>        {
>            struct dirent **namelist;
>            int n;
> 
>            n = scandir(".", &namelist, NULL, alphasort);
>            if (n == -1) {
>                perror("scandir");
>                exit(EXIT_FAILURE);
>            }
> 
>            while (n--) {
>                printf("%s\n", namelist[n]->d_name);
>                free(namelist[n]);
>            }
>            free(namelist);
> 
>            exit(EXIT_SUCCESS);
>        }

Confirmed to be present in man-pages-4.10 (first packaged in Debian in
4.10-1) and also confirmed working, hence this bug could be closed
accordingly.

Cheers,
Flo
[signature.asc (application/pgp-signature, inline)]

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Thu Mar 9 10:02:40 2023; Machine Name: bembo

Debian Bug tracking system

Debbugs is free software and licensed under the terms of the GNU Public License version 2. The current version can be obtained from https://bugs.debian.org/debbugs-source/.

Copyright © 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson, 2005-2017 Don Armstrong, and many other contributors.