threads / discuss / 41563

50a6c8ef - xmalloc_array

Subject: 50a6c8ef - xmalloc_array

## tl;dr

18 messages between Feb 29, 2016 and May 10, 2016.

replies: 17people: 6as markdown or json

Torsten Bögershausen· Feb 29, 2016, 06:30 UTC · lore

I haven't digged further, but trying to verify t9115 under Windows gave this:

compat/mingw.c: In function 'mingw_spawnve_fd':
compat/mingw.c:1072:10: warning: implicit declaration of function 
'xmalloc_array' [-Wimplicit-function-declaration]
   wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
           ^
compat/mingw.c:1072:8: warning: assignment makes pointer from integer without a 
cast [-Wint-conversion]
   wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
         ^
--- and later ---

libgit.a(mingw.o): In function `mingw_spawnve_fd': ..... compat/mingw.c:1072: undefined reference to `xmalloc_array' collect2.exe: error: ld returned 1 exit status Makefile:2014: recipe for target 'git-credential-store.exe' failed make: *** [git-credential-store.exe] Error 1

Jeff King· Feb 29, 2016, 09:28 UTC · re: Torsten Bögershausen · lore

[PATCH] compat/mingw: brown paper bag fix for 50a6c8e

On Mon, Feb 29, 2016 at 07:30:02AM +0100, Torsten Bögershausen wrote:
Show 8 quoted lines
> I haven't digged further,
> but trying to verify t9115 under Windows gave this:
> 
> compat/mingw.c: In function 'mingw_spawnve_fd':
> compat/mingw.c:1072:10: warning: implicit declaration of function
> 'xmalloc_array' [-Wimplicit-function-declaration]
>   wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
>           ^
Yikes.
-- >8 --
Subject: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

Commit 50a6c8e (use st_add and st_mult for allocation size computation, 2016-02-22) fixed up many xmalloc call-sites including ones in compat/mingw.c.

But I screwed up one of them, which was half-converted to ALLOC_ARRAY, using a very early prototype of the function. And I never caught it because I don't build on Windows.

Signed-off-by: Jeff King <peff@peff.net>
---
I think this means "master" is broken for mingw builds.

Sorry, Windows people, for breaking your build. I'm happy to hold back such repo-wide cleanups from the mingw code in the future, since I can't actually compile them. But the flipside is that if I _do_ improve things, you don't get the benefit until somebody manually ports it over.

 compat/mingw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index cfedcf9..54c82ec 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1069,7 +1069,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
 			free(quoted);
 	}
 
-	wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
+	ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
 	xutftowcs(wargs, args.buf, 2 * args.len + 1);
 	strbuf_release(&args);
 
-- 
2.8.0.rc0.276.gddf4100
Torsten Bögershausen· Feb 29, 2016, 09:56 UTC · re: Jeff King · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

Thanks for the fast-patch.
I manually copied the patch, But there are more probles, it seems.
$ git diff
diff --git a/compat/mingw.c b/compat/mingw.c
index cfedcf9..b1163f2 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1069,7 +1069,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char 
**argv, char **deltaen
                         free(quoted);
         }

-       wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
+       wargs = ALLOC_ARRAY(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
         xutftowcs(wargs, args.buf, 2 * args.len + 1);
         strbuf_release(&args);


tb@torbogwm MINGW64 ~/Users/tb/projects/git/tb ((2273582...))
$ make
     CC compat/mingw.o
In file included from compat/mingw.c:1:0:
compat/mingw.c: In function 'mingw_spawnve_fd':
compat/../git-compat-util.h:769:60: error: invalid type argument of unary '*' 
(have 'size_t {aka long long unsigned int}')
  #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
                                                             ^
compat/mingw.c:1072:10: note: in expansion of macro 'ALLOC_ARRAY'
   wargs = ALLOC_ARRAY(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
           ^
Makefile:1948: recipe for target 'compat/mingw.o' failed
make: *** [compat/mingw.o] Error 1
Jeff King· Feb 29, 2016, 10:02 UTC · re: Torsten Bögershausen · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

On Mon, Feb 29, 2016 at 10:56:22AM +0100, Torsten Bögershausen wrote:
Show 18 quoted lines
> Thanks for the fast-patch.
> 
> I manually copied the patch, But there are more probles, it seems.
> 
> $ git diff
> diff --git a/compat/mingw.c b/compat/mingw.c
> index cfedcf9..b1163f2 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1069,7 +1069,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const
> char **argv, char **deltaen
>                         free(quoted);
>         }
> 
> -       wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
> +       wargs = ALLOC_ARRAY(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
>         xutftowcs(wargs, args.buf, 2 * args.len + 1);
>         strbuf_release(&args);

Argh. Let me write "git commit -a" on the inside of my brown paper bag, so that I actually send out the fix sitting in my working tree, not the half-finished thing I ran "git add" on.

-- >8 --
Subject: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

Commit 50a6c8e (use st_add and st_mult for allocation size computation, 2016-02-22) fixed up many xmalloc call-sites including ones in compat/mingw.c.

But I screwed up one of them, which was half-converted to ALLOC_ARRAY, using a very early prototype of the function. And I never caught it because I don't build on Windows.

Signed-off-by: Jeff King <peff@peff.net>
---
 compat/mingw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index cfedcf9..54c82ec 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1069,7 +1069,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
 			free(quoted);
 	}
 
-	wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
+	ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
 	xutftowcs(wargs, args.buf, 2 * args.len + 1);
 	strbuf_release(&args);
 
-- 
2.8.0.rc0.276.gddf4100
Torsten Bögershausen· Feb 29, 2016, 10:40 UTC · re: Jeff King · lore

Compiler warning under cygwin/mingw (was: fix for 50a6c8e)

That compiles OK, thanks.

Sorry for high-jacking this thread, but while compiling under CYGWIN, found one warning:

    LINK git-credential-store.exe
     CC daemon.o
daemon.c: In function ‘drop_privileges’:
daemon.c:1136:15: warning: implicit declaration of function ‘initgroups’ 
[-Wimplicit-function-declaration]
   if (cred && (initgroups(cred->pass->pw_name, cred->gid) ||
                ^

t9115 doesn't pass, NTFS doesn't like the non-UTF filenames, it seams. Probably the same problem as under Mac OS /HFS+- -----------------------

And MINGW is not happy for other reasons:
builtin/rev-parse.c: In function 'cmd_rev_parse':
builtin/rev-parse.c:775:12: warning: implicit declaration of function 
'realpath' [-Wimplicit-function-declaration]
        if (!realpath(gitdir, absolute_path))
             ^
     CC builtin/revert.o
     CC builtin/write-tree.o
     LINK git.exe
builtin/rev-parse.o: In function `cmd_rev_parse':
C:\Users\tb\projects\git\tb/builtin/rev-parse.c:775: undefined reference to 
`realpath'
collect2.exe: error: ld returned 1 exit status
Makefile:1725: recipe for target 'git.exe' failed
make: *** [git.exe] Error 1
Jeff King· Feb 29, 2016, 10:47 UTC · re: Torsten Bögershausen · lore

Re: Compiler warning under cygwin/mingw (was: fix for 50a6c8e)

On Mon, Feb 29, 2016 at 11:40:59AM +0100, Torsten Bögershausen wrote:
Show 11 quoted lines
> That compiles OK, thanks.
> 
> Sorry for high-jacking this thread, but while compiling under CYGWIN,
> found one warning:
> 
>    LINK git-credential-store.exe
>     CC daemon.o
> daemon.c: In function ‘drop_privileges’:
> daemon.c:1136:15: warning: implicit declaration of function ‘initgroups’
> [-Wimplicit-function-declaration]
>   if (cred && (initgroups(cred->pass->pw_name, cred->gid) ||
Interesting that it doesn't later complain in the link step. :)

You should probably be compiling with the NO_INITGROUPS knob on that platform.

> t9115 doesn't pass,  NTFS doesn't like the non-UTF filenames, it seams.
> Probably the same problem as under Mac OS /HFS+-
> -----------------------
No comment from me on that one.
Show 7 quoted lines
> And MINGW is not happy for other reasons:
> 
> builtin/rev-parse.c: In function 'cmd_rev_parse':
> builtin/rev-parse.c:775:12: warning: implicit declaration of function
> 'realpath' [-Wimplicit-function-declaration]
>        if (!realpath(gitdir, absolute_path))
>             ^

I guess you're building "pu"; that is only in sg/completion-updates. I don't know if our custom real_path() would suffice there. You might want to ping the author. The patch is:

  http://article.gmane.org/gmane.comp.version-control.git/287462
-Peff
SZEDER Gábor· Feb 29, 2016, 14:05 UTC · re: Jeff King · lore

Re: Compiler warning under cygwin/mingw (was: fix for 50a6c8e)

Hi,
Show 13 quoted lines
> > And MINGW is not happy for other reasons:
> >
> > builtin/rev-parse.c: In function 'cmd_rev_parse':
> > builtin/rev-parse.c:775:12: warning: implicit declaration of function
> > 'realpath' [-Wimplicit-function-declaration]
> >        if (!realpath(gitdir, absolute_path))
> >             ^
> 
> I guess you're building "pu"; that is only in sg/completion-updates. I
> don't know if our custom real_path() would suffice there. You might want
> to ping the author. The patch is:
> 
>   http://article.gmane.org/gmane.comp.version-control.git/287462

Oh, I was not aware that there is a custom real_path() that is preferred over the system realpath(). I don't see why our real_path() would not suffice, it even makes the code a tad shorter.

I will include the patch below in the reroll.

Best, Gábor

 ----  >8  ----
Subject: [PATCH] fixup! rev-parse: add '--absolute-git-dir' option
---
 builtin/rev-parse.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index 90a4dd6032c0..d6d9a82c77c4 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -762,10 +762,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 					if (!gitdir && !prefix)
 						gitdir = ".git";
 					if (gitdir) {
-						char absolute_path[PATH_MAX];
-						if (!realpath(gitdir, absolute_path))
-							die_errno(_("unable to get absolute path"));
-						puts(absolute_path);
+						puts(real_path(gitdir));
 						continue;
 					}
 				}
-- 
2.7.2.410.g92cb358
Junio C Hamano· Apr 12, 2016, 23:20 UTC · re: SZEDER Gábor · lore

Re: Compiler warning under cygwin/mingw

SZEDER Gábor <szeder@ira.uka.de> writes:
Show 21 quoted lines
> Hi,
>
>> > And MINGW is not happy for other reasons:
>> >
>> > builtin/rev-parse.c: In function 'cmd_rev_parse':
>> > builtin/rev-parse.c:775:12: warning: implicit declaration of function
>> > 'realpath' [-Wimplicit-function-declaration]
>> >        if (!realpath(gitdir, absolute_path))
>> >             ^
>> 
>> I guess you're building "pu"; that is only in sg/completion-updates. I
>> don't know if our custom real_path() would suffice there. You might want
>> to ping the author. The patch is:
>> 
>>   http://article.gmane.org/gmane.comp.version-control.git/287462
>
> Oh, I was not aware that there is a custom real_path() that is
> preferred over the system realpath().  I don't see why our real_path()
> would not suffice, it even makes the code a tad shorter.
>
> I will include the patch below in the reroll.

A friendly ping to see if I am missing new development that followed this message...

Show 28 quoted lines
>
> Best,
> Gábor
>
>
>  ----  >8  ----
> Subject: [PATCH] fixup! rev-parse: add '--absolute-git-dir' option
>
> ---
>  builtin/rev-parse.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index 90a4dd6032c0..d6d9a82c77c4 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -762,10 +762,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
>  					if (!gitdir && !prefix)
>  						gitdir = ".git";
>  					if (gitdir) {
> -						char absolute_path[PATH_MAX];
> -						if (!realpath(gitdir, absolute_path))
> -							die_errno(_("unable to get absolute path"));
> -						puts(absolute_path);
> +						puts(real_path(gitdir));
>  						continue;
>  					}
>  				}
Junio C Hamano· May 10, 2016, 18:29 UTC · re: SZEDER Gábor · lore

Re: [PATCH 0/6] modernize t1500

Eric Sunshine <sunshine@sunshineco.com> writes:
Show 6 quoted lines
>   t1500: test_rev_parse: facilitate future test enhancements
>   t1500: reduce dependence upon global state
>   t1500: avoid changing working directory outside of tests
>   t1500: avoid setting configuration options outside of tests
>   t1500: avoid setting environment variables outside of tests
>   t1500: be considerate to future potential tests

When you reroll sg/completion-updates series (87a213f^..2be685a, 21 patches), please pay attention to this series, as it changes the way you would check the output from your "--absolute-git-dir" option.

Ramsay Jones· Feb 29, 2016, 12:32 UTC · re: Torsten Bögershausen · lore

Re: Compiler warning under cygwin/mingw

On 29/02/16 10:40, Torsten Bögershausen wrote:
Show 11 quoted lines
> That compiles OK, thanks.
> 
> 
> Sorry for high-jacking this thread, but while compiling under CYGWIN,
> found one warning:
> 
>    LINK git-credential-store.exe
>     CC daemon.o
> daemon.c: In function ‘drop_privileges’:
> daemon.c:1136:15: warning: implicit declaration of function ‘initgroups’ [-Wimplicit-function-declaration]
>   if (cred && (initgroups(cred->pass->pw_name, cred->gid) ||

Yeah, this has been there for a while - except it depends on which version of the header files you have. (Some may not see the warning).

I have 'fixed' this twice before, then updated my installation and a change to the system headers broke it again! (The headers are currently 'broken'). So, I got tired of fixing it up and have left it a while - you never know a new update may fix it! ;-)

[I personally don't use the git daemon on cygwin, so I don't know if this a problem in practice.]

ATB, Ramsay Jones

Ramsay Jones· Mar 3, 2016, 03:33 UTC · re: Ramsay Jones · lore

Re: Compiler warning under cygwin/mingw

On 29/02/16 12:32, Ramsay Jones wrote:
Show 25 quoted lines
> 
> 
> On 29/02/16 10:40, Torsten Bögershausen wrote:
>> That compiles OK, thanks.
>>
>>
>> Sorry for high-jacking this thread, but while compiling under CYGWIN,
>> found one warning:
>>
>>    LINK git-credential-store.exe
>>     CC daemon.o
>> daemon.c: In function ‘drop_privileges’:
>> daemon.c:1136:15: warning: implicit declaration of function ‘initgroups’ [-Wimplicit-function-declaration]
>>   if (cred && (initgroups(cred->pass->pw_name, cred->gid) ||
> 
> Yeah, this has been there for a while - except it depends on which version
> of the header files you have. (Some may not see the warning).
> 
> I have 'fixed' this twice before, then updated my installation and
> a change to the system headers broke it again! (The headers are
> currently 'broken'). So, I got tired of fixing it up and have left
> it a while - you never know a new update may fix it! ;-)
> 
> [I personally don't use the git daemon on cygwin, so I don't know
> if this a problem in practice.]

BTW, I forgot to mention that I have had a patch in my local repo for ages which addresses this issue. However, although this patch fixes the problem for me, with the header files I currently have installed, it would just as easily _introduce_ this warning for those that don't currently see it! ;-)

I suppose that I could send a patch which sets NO_INITGROUPS in the Makefile, until the system header files are fixed. What do you think?

The correct solution is to fix the <grp.h> header file. I have been a bit reluctant to tackle that, because I'm not familiar with the cygwin project development process. Since Newlib is an upstream project to cygwin, should I go there first/instead?

Anyway, I had a quick squint at the header and I think it needs to be changed something like the diff below. (I've also attached the new grp.h file).

[Note: I didn't know what to do about _PATH_GROUP, setgrfile(), group_from_gid() and setgroupent(), so I punted on those!]

Now, If only we knew someone who could try introducing such a fix to the cygwin project ...

ATB, Ramsay Jones -- >8 --

diff --git a/usr/include/grp.h b/grp.h
index c3a5a67..f2f1902 100644
--- a/usr/include/grp.h
+++ b/grp.h
@@ -67,25 +67,27 @@ extern "C" {
 #ifndef __INSIDE_CYGWIN__
 struct group	*getgrgid (gid_t);
 struct group	*getgrnam (const char *);
+#if defined __POSIX_VISIBLE || defined __BSD_VISIBLE
 int		 getgrnam_r (const char *, struct group *,
 			char *, size_t, struct group **);
 int		 getgrgid_r (gid_t, struct group *,
 			char *, size_t, struct group **);
-#ifndef _POSIX_SOURCE
-struct group	*getgrent (void);
+#endif
+#if defined __BSD_VISIBLE || defined _XOPEN_SOURCE_EXTENDED
 void		 setgrent (void);
+#if __XSI_VISIBLE >= 700
+struct group	*getgrent (void);
 void		 endgrent (void);
+#endif
+#endif
+#if defined __BSD_VISIBLE
+int		 initgroups (const char *, gid_t);
+#endif
 #ifndef __CYGWIN__
-void		 setgrfile (const char *);
-#endif /* !__CYGWIN__ */
-#ifndef _XOPEN_SOURCE
-#ifndef __CYGWIN__
+void		 setgrfile (const char *); /* 4.3BSD-Reno & Minix */
 char		*group_from_gid (gid_t, int);
-int		 setgroupent (int);
+int		 setgroupent (int); /* 4.3BSD-Reno & Mac OS X */
 #endif /* !__CYGWIN__ */
-int		 initgroups (const char *, gid_t);
-#endif /* !_XOPEN_SOURCE */
-#endif /* !_POSIX_SOURCE */
 #endif /* !__INSIDE_CYGWIN__ */
 
 #ifdef __cplusplus


/*	$NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $	*/

/*-
 * Copyright (c) 1989, 1993
 *	The Regents of the University of California.  All rights reserved.
 * (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)grp.h	8.2 (Berkeley) 1/21/94
 */

#ifndef _GRP_H_
#define	_GRP_H_

#include <sys/cdefs.h>
#include <sys/types.h>
#ifdef __CYGWIN__
#include <cygwin/grp.h>
#endif

#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
#define	_PATH_GROUP		"/etc/group"
#endif

struct group {
	char	*gr_name;		/* group name */
	char	*gr_passwd;		/* group password */
	gid_t	gr_gid;			/* group id */
	char	**gr_mem;		/* group members */
};

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __INSIDE_CYGWIN__
struct group	*getgrgid (gid_t);
struct group	*getgrnam (const char *);
#if defined __POSIX_VISIBLE || defined __BSD_VISIBLE
int		 getgrnam_r (const char *, struct group *,
			char *, size_t, struct group **);
int		 getgrgid_r (gid_t, struct group *,
			char *, size_t, struct group **);
#endif
#if defined __BSD_VISIBLE || defined _XOPEN_SOURCE_EXTENDED
void		 setgrent (void);
#if __XSI_VISIBLE >= 700
struct group	*getgrent (void);
void		 endgrent (void);
#endif
#endif
#if defined __BSD_VISIBLE
int		 initgroups (const char *, gid_t);
#endif
#ifndef __CYGWIN__
void		 setgrfile (const char *); /* 4.3BSD-Reno & Minix */
char		*group_from_gid (gid_t, int);
int		 setgroupent (int); /* 4.3BSD-Reno & Mac OS X */
#endif /* !__CYGWIN__ */
#endif /* !__INSIDE_CYGWIN__ */

#ifdef __cplusplus
}
#endif

#endif /* !_GRP_H_ */
Ramsay Jones· Mar 3, 2016, 05:25 UTC · re: Ramsay Jones · lore

Re: Compiler warning under cygwin/mingw

On 03/03/16 03:33, Ramsay Jones wrote:
Show 47 quoted lines
> 
> 
> On 29/02/16 12:32, Ramsay Jones wrote:
>>
>>
>> On 29/02/16 10:40, Torsten Bögershausen wrote:
>>> That compiles OK, thanks.
>>>
>>>
>>> Sorry for high-jacking this thread, but while compiling under CYGWIN,
>>> found one warning:
>>>
>>>    LINK git-credential-store.exe
>>>     CC daemon.o
>>> daemon.c: In function ‘drop_privileges’:
>>> daemon.c:1136:15: warning: implicit declaration of function ‘initgroups’ [-Wimplicit-function-declaration]
>>>   if (cred && (initgroups(cred->pass->pw_name, cred->gid) ||
>>
>> Yeah, this has been there for a while - except it depends on which version
>> of the header files you have. (Some may not see the warning).
>>
>> I have 'fixed' this twice before, then updated my installation and
>> a change to the system headers broke it again! (The headers are
>> currently 'broken'). So, I got tired of fixing it up and have left
>> it a while - you never know a new update may fix it! ;-)
>>
>> [I personally don't use the git daemon on cygwin, so I don't know
>> if this a problem in practice.]
> 
> BTW, I forgot to mention that I have had a patch in my local repo for
> ages which addresses this issue. However, although this patch fixes
> the problem for me, with the header files I currently have installed, it
> would just as easily _introduce_ this warning for those that don't
> currently see it! ;-)
> 
> I suppose that I could send a patch which sets NO_INITGROUPS in the
> Makefile, until the system header files are fixed. What do you think?
> 
> The correct solution is to fix the <grp.h> header file. I have been
> a bit reluctant to tackle that, because I'm not familiar with the
> cygwin project development process. Since Newlib is an upstream
> project to cygwin, should I go there first/instead?
> 
> Anyway, I had a quick squint at the header and I think it needs to
> be changed something like the diff below. (I've also attached the
> new grp.h file).
> 

And, of course, I made a mess of it! It was only supposed to be a 'something like this' patch, but still ... :-D

> [Note: I didn't know what to do about _PATH_GROUP, setgrfile(),
> group_from_gid() and setgroupent(), so I punted on those!]

Also, the comments on setgrfile() and setgroupent() were just notes to myself, which I didn't intend to send ...

So, more like the diff below.

ATB, Ramsay Jones

-- >8 --
diff --git a/usr/include/grp.h b/grp.h
index c3a5a67..c04fd63 100644
--- a/usr/include/grp.h
+++ b/grp.h
@@ -67,25 +67,25 @@ extern "C" {
 #ifndef __INSIDE_CYGWIN__
 struct group	*getgrgid (gid_t);
 struct group	*getgrnam (const char *);
+#if defined __POSIX_VISIBLE || defined __BSD_VISIBLE
 int		 getgrnam_r (const char *, struct group *,
 			char *, size_t, struct group **);
 int		 getgrgid_r (gid_t, struct group *,
 			char *, size_t, struct group **);
-#ifndef _POSIX_SOURCE
-struct group	*getgrent (void);
+#endif
+#if defined __BSD_VISIBLE || defined __XSI_VISIBLE
 void		 setgrent (void);
+struct group	*getgrent (void);
 void		 endgrent (void);
+#endif
+#if defined __BSD_VISIBLE
+int		 initgroups (const char *, gid_t);
+#endif
 #ifndef __CYGWIN__
 void		 setgrfile (const char *);
-#endif /* !__CYGWIN__ */
-#ifndef _XOPEN_SOURCE
-#ifndef __CYGWIN__
 char		*group_from_gid (gid_t, int);
 int		 setgroupent (int);
 #endif /* !__CYGWIN__ */
-int		 initgroups (const char *, gid_t);
-#endif /* !_XOPEN_SOURCE */
-#endif /* !_POSIX_SOURCE */
 #endif /* !__INSIDE_CYGWIN__ */
 
 #ifdef __cplusplus


/*	$NetBSD: grp.h,v 1.7 1995/04/29 05:30:40 cgd Exp $	*/

/*-
 * Copyright (c) 1989, 1993
 *	The Regents of the University of California.  All rights reserved.
 * (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *	This product includes software developed by the University of
 *	California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)grp.h	8.2 (Berkeley) 1/21/94
 */

#ifndef _GRP_H_
#define	_GRP_H_

#include <sys/cdefs.h>
#include <sys/types.h>
#ifdef __CYGWIN__
#include <cygwin/grp.h>
#endif

#if !defined(_POSIX_SOURCE) && !defined(_XOPEN_SOURCE)
#define	_PATH_GROUP		"/etc/group"
#endif

struct group {
	char	*gr_name;		/* group name */
	char	*gr_passwd;		/* group password */
	gid_t	gr_gid;			/* group id */
	char	**gr_mem;		/* group members */
};

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __INSIDE_CYGWIN__
struct group	*getgrgid (gid_t);
struct group	*getgrnam (const char *);
#if defined __POSIX_VISIBLE || defined __BSD_VISIBLE
int		 getgrnam_r (const char *, struct group *,
			char *, size_t, struct group **);
int		 getgrgid_r (gid_t, struct group *,
			char *, size_t, struct group **);
#endif
#if defined __BSD_VISIBLE || defined __XSI_VISIBLE
void		 setgrent (void);
struct group	*getgrent (void);
void		 endgrent (void);
#endif
#if defined __BSD_VISIBLE
int		 initgroups (const char *, gid_t);
#endif
#ifndef __CYGWIN__
void		 setgrfile (const char *);
char		*group_from_gid (gid_t, int);
int		 setgroupent (int);
#endif /* !__CYGWIN__ */
#endif /* !__INSIDE_CYGWIN__ */

#ifdef __cplusplus
}
#endif

#endif /* !_GRP_H_ */
Junio C Hamano· Feb 29, 2016, 19:10 UTC · re: Jeff King · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

Jeff King <peff@peff.net> writes:
Show 24 quoted lines
> On Mon, Feb 29, 2016 at 10:56:22AM +0100, Torsten Bögershausen wrote:
>
>> Thanks for the fast-patch.
>> 
>> I manually copied the patch, But there are more probles, it seems.
>> 
>> $ git diff
>> diff --git a/compat/mingw.c b/compat/mingw.c
>> index cfedcf9..b1163f2 100644
>> --- a/compat/mingw.c
>> +++ b/compat/mingw.c
>> @@ -1069,7 +1069,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const
>> char **argv, char **deltaen
>>                         free(quoted);
>>         }
>> 
>> -       wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
>> +       wargs = ALLOC_ARRAY(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
>>         xutftowcs(wargs, args.buf, 2 * args.len + 1);
>>         strbuf_release(&args);
>
> Argh. Let me write "git commit -a" on the inside of my brown paper bag,
> so that I actually send out the fix sitting in my working tree, not the
> half-finished thing I ran "git add" on.

Just to make sure that I am not confused, what you wrote below matches what I received from you two message upthread.

I am assuming that it is intended that the two messages from you have the same patch, and the assignment of ALLOC_ARRAY to wargs was a bug Torsten introduced only to his tree when cutting and pasting.

With that assumption, will queue this one (or the original one, which to me is the same thing).

Thanks.
Show 28 quoted lines
> -- >8 --
> Subject: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e
>
> Commit 50a6c8e (use st_add and st_mult for allocation size
> computation, 2016-02-22) fixed up many xmalloc call-sites
> including ones in compat/mingw.c.
>
> But I screwed up one of them, which was half-converted to
> ALLOC_ARRAY, using a very early prototype of the function.
> And I never caught it because I don't build on Windows.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
>  compat/mingw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/mingw.c b/compat/mingw.c
> index cfedcf9..54c82ec 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1069,7 +1069,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
>  			free(quoted);
>  	}
>  
> -	wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
> +	ALLOC_ARRAY(wargs, st_add(st_mult(2, args.len), 1));
>  	xutftowcs(wargs, args.buf, 2 * args.len + 1);
>  	strbuf_release(&args);
Jeff King· Feb 29, 2016, 21:36 UTC · re: Junio C Hamano · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

On Mon, Feb 29, 2016 at 11:10:09AM -0800, Junio C Hamano wrote:
Show 18 quoted lines
> >> -       wargs = xmalloc_array(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
> >> +       wargs = ALLOC_ARRAY(st_add(st_mult(2, args.len), 1), sizeof(wchar_t));
> >>         xutftowcs(wargs, args.buf, 2 * args.len + 1);
> >>         strbuf_release(&args);
> >
> > Argh. Let me write "git commit -a" on the inside of my brown paper bag,
> > so that I actually send out the fix sitting in my working tree, not the
> > half-finished thing I ran "git add" on.
> 
> Just to make sure that I am not confused, what you wrote below
> matches what I received from you two message upthread.
> 
> I am assuming that it is intended that the two messages from you
> have the same patch, and the assignment of ALLOC_ARRAY to wargs was
> a bug Torsten introduced only to his tree when cutting and pasting.
> 
> With that assumption, will queue this one (or the original one,
> which to me is the same thing).
Oh, <phew>. I am only half as incompetent as I thought, then.

I didn't even re-check what I sent, and just assumed Torsten was quoting it exactly (I _did_ write something like that while making the fix, and assumed I had just failed to properly commit).

So yes, what I sent both times is the right thing. ;)
-Peff
Torsten Bögershausen· Mar 1, 2016, 05:49 UTC · re: Jeff King · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

Oh, <phew>. I am only half as incompetent as I thought, then.

I didn't even re-check what I sent, and just assumed Torsten was quoting it exactly (I _did_ write something like that while making the fix, and assumed I had just failed to properly commit).

So yes, what I sent both times is the right thing. ;)

-Peff --

I have no clue how my copy-paste programing could go so bad :-( Sorry for the confusion, compat/mingw.c compiles now.

----------------

However, suspecting jk/epipe-in-async, I don't know if we can do something against this warning:

  CC run-command.o
run-command.c: In function 'async_exit':
run-command.c:631:1: warning: 'noreturn' function does return
  }
  ^
Jeff King· Mar 1, 2016, 05:54 UTC · re: Torsten Bögershausen · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

On Tue, Mar 01, 2016 at 06:49:43AM +0100, Torsten Bögershausen wrote:
Show 8 quoted lines
> However, suspecting jk/epipe-in-async, I don't know if we can do
> something against this warning:
> 
>  CC run-command.o
> run-command.c: In function 'async_exit':
> run-command.c:631:1: warning: 'noreturn' function does return
>  }
>  ^

The only thing that function does is call pthread_exit(), which should also be marked NORETURN. Looks like the one in compat/win32/pthread.h isn't?

-Peff
Johannes Schindelin· Mar 1, 2016, 13:52 UTC · re: Jeff King · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

Hi Peff,
On Tue, 1 Mar 2016, Jeff King wrote:
Show 11 quoted lines
> On Tue, Mar 01, 2016 at 06:49:43AM +0100, Torsten Bögershausen wrote:
> 
> > However, suspecting jk/epipe-in-async, I don't know if we can do
> > something against this warning:
> > 
> >  CC run-command.o run-command.c: In function 'async_exit':
> >  run-command.c:631:1: warning: 'noreturn' function does return } ^
> 
> The only thing that function does is call pthread_exit(), which should
> also be marked NORETURN. Looks like the one in compat/win32/pthread.h
> isn't?
Correct. Expect a patch momentarily.

Ciao, Dscho

Johannes Schindelin· Feb 29, 2016, 13:01 UTC · re: Jeff King · lore

Re: [PATCH] compat/mingw: brown paper bag fix for 50a6c8e

Hi Peff,
On Mon, 29 Feb 2016, Jeff King wrote:
Show 6 quoted lines
> I think this means "master" is broken for mingw builds.
> 
> Sorry, Windows people, for breaking your build. I'm happy to hold back
> such repo-wide cleanups from the mingw code in the future, since I can't
> actually compile them. But the flipside is that if I _do_ improve
> things, you don't get the benefit until somebody manually ports it over.

No, I do not think that you need to hold back cleanups. We will catch such issues before long, anyway.

Thanks for all your hard work! Dscho

← back to recent threads