# [PATCH] Don't rely on unspecified behavior

11 messages from 2007-07-28 to 2007-07-28. Participants: Thomas Schwinge, Thomas Glanzmann, Johannes Schindelin.
Thread: https://gitlist.dev/t/9277

## Thomas Schwinge, 2007-07-28 16:39

Subject: [PATCH] Support building on GNU/Hurd
Message-ID: <11856407793933-git-send-email-tschwinge@gnu.org>
URL: https://gitlist.dev/e/11856407793933-git-send-email-tschwinge%40gnu.org

```
GNU/Hurd systems don't have strlcpy either.

Signed-off-by: Thomas Schwinge <tschwinge@gnu.org>
---
 Makefile |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index 2fea115..8d9a01b 100644
--- a/Makefile
+++ b/Makefile
@@ -458,6 +458,10 @@ ifeq ($(uname_S),AIX)
 	NO_STRLCPY = YesPlease
 	NEEDS_LIBICONV=YesPlease
 endif
+ifeq ($(uname_S),GNU)
+	# GNU/Hurd
+	NO_STRLCPY=YesPlease
+endif
 ifeq ($(uname_S),IRIX64)
 	NO_IPV6=YesPlease
 	NO_SETENV=YesPlease
-- 
1.5.3.rc3.26.g6c58-dirty

```

## Thomas Schwinge, 2007-07-28 16:39

Subject: [PATCH] Don't rely on unspecified behavior
Message-ID: <11856407791617-git-send-email-tschwinge@gnu.org>
URL: https://gitlist.dev/e/11856407791617-git-send-email-tschwinge%40gnu.org
In-Reply-To: <11856407793933-git-send-email-tschwinge@gnu.org>

```
Calling access(p, m) with p == NULL is not specified, so don't do that.  On
GNU/Hurd systems doing so will result in an SIGSEGV.

Signed-off-by: Thomas Schwinge <tschwinge@gnu.org>
---
 builtin-add.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-add.c b/builtin-add.c
index 5e6748f..c13c738 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -74,7 +74,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
 	path = git_path("info/exclude");
 	if (!access(path, R_OK))
 		add_excludes_from_file(dir, path);
-	if (!access(excludes_file, R_OK))
+	if (excludes_file != NULL && !access(excludes_file, R_OK))
 		add_excludes_from_file(dir, excludes_file);
 
 	/*
-- 
1.5.3.rc3.26.g6c58-dirty

```

## Thomas Glanzmann, 2007-07-28 17:39

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <20070728173948.GD23337@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20070728173948.GD23337%40cip.informatik.uni-erlangen.de
In-Reply-To: <11856407791617-git-send-email-tschwinge@gnu.org>

```
Hello,

> Calling access(p, m) with p == NULL is not specified, so don't do
> that.  On GNU/Hurd systems doing so will result in an SIGSEGV.

a friend of mine choked on this one when tried git for the second time
(the first time "git-repack -a -d -f" screwed his repository after the
initial checkout. This is fixed for a long time). Lucky me that he had
his libusbdriver in LD_PRELOAD which could not handle the NULL argument.
And I always thought libc would make the check before it does the system
call or does GNU/hurts not use the gnu libc?

	Thomas

```

## Thomas Schwinge, 2007-07-28 18:25

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <20070728182542.GA22651@fencepost.gnu.org>
URL: https://gitlist.dev/e/20070728182542.GA22651%40fencepost.gnu.org
In-Reply-To: <20070728173948.GD23337@cip.informatik.uni-erlangen.de>

```
Hello!

On Sat, Jul 28, 2007 at 07:39:48PM +0200, Thomas Glanzmann wrote:
> > Calling access(p, m) with p == NULL is not specified, so don't do
> > that.  On GNU/Hurd systems doing so will result in an SIGSEGV.
> 
> a friend of mine choked on this one when tried git for the second time
> (the first time "git-repack -a -d -f" screwed his repository after the
> initial checkout. This is fixed for a long time). Lucky me that he had
> his libusbdriver in LD_PRELOAD which could not handle the NULL argument.
> And I always thought libc would make the check before it does the system
> call or does GNU/hurts not use the gnu libc?

GNU/Hurd systems do (obviously ;-) use the GNU libc.  The glibc
maintainer Roland McGrath explicitly told me that ``access (NULL, m)''
shall not be caught as it is not specified and thus must not be invoked
like this.


I noticed that the patch I sent was prepared for an old version of the
file.  I'll send an updated patch that applies to the current revision.


Regards,
 Thomas

```

## Thomas Schwinge, 2007-07-28 18:26

Subject: [PATCH] Don't rely on unspecified behavior
Message-ID: <11856471952272-git-send-email-tschwinge@gnu.org>
URL: https://gitlist.dev/e/11856471952272-git-send-email-tschwinge%40gnu.org
In-Reply-To: <20070728173948.GD23337@cip.informatik.uni-erlangen.de>

```
Calling access(p, m) with p == NULL is not specified, so don't do that.  On
GNU/Hurd systems doing so will result in a SIGSEGV.

Signed-off-by: Thomas Schwinge <tschwinge@gnu.org>
---
 builtin-add.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/builtin-add.c b/builtin-add.c
index 7345479..de5c108 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -60,7 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
 		path = git_path("info/exclude");
 		if (!access(path, R_OK))
 			add_excludes_from_file(dir, path);
-		if (!access(excludes_file, R_OK))
+		if (excludes_file != NULL && !access(excludes_file, R_OK))
 			add_excludes_from_file(dir, excludes_file);
 	}
 
-- 
1.5.3.rc3.26.g6c58-dirty

```

## Johannes Schindelin, 2007-07-28 19:30

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <Pine.LNX.4.64.0707282028130.14781@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0707282028130.14781%40racer.site
In-Reply-To: <11856471952272-git-send-email-tschwinge@gnu.org>

```
Hi,

On Sat, 28 Jul 2007, Thomas Schwinge wrote:

> Calling access(p, m) with p == NULL is not specified, so don't do that.  On
> GNU/Hurd systems doing so will result in a SIGSEGV.
> 
> Signed-off-by: Thomas Schwinge <tschwinge@gnu.org>
> ---

Isn't this the same patch as you sent before?

>  builtin-add.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/builtin-add.c b/builtin-add.c
> index 7345479..de5c108 100644
> --- a/builtin-add.c
> +++ b/builtin-add.c
> @@ -60,7 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
>  		path = git_path("info/exclude");
>  		if (!access(path, R_OK))
>  			add_excludes_from_file(dir, path);
> -		if (!access(excludes_file, R_OK))
> +		if (excludes_file != NULL && !access(excludes_file, R_OK))

We usually omit the "!= NULL"; see the other source code in git.git.

Ciao,
Dscho

```

## Thomas Glanzmann, 2007-07-28 19:34

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <20070728193402.GE23337@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20070728193402.GE23337%40cip.informatik.uni-erlangen.de
In-Reply-To: <Pine.LNX.4.64.0707282028130.14781@racer.site>

```
Hello Dscho,

> Isn't this the same patch as you sent before?

> > @@ -74,7 +74,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
> > @@ -60,7 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
       ~~~~~ ~~~~~                                                                            ~

The offset of the diff has changed. Not that git couldn't sort it out by
itself. And the function had one or more parameters less.

	Thomas

```

## Thomas Schwinge, 2007-07-28 19:43

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <20070728194306.GA32203@fencepost.gnu.org>
URL: https://gitlist.dev/e/20070728194306.GA32203%40fencepost.gnu.org
In-Reply-To: <Pine.LNX.4.64.0707282028130.14781@racer.site>

```
Hello!

On Sat, Jul 28, 2007 at 08:30:07PM +0100, Johannes Schindelin wrote:
> On Sat, 28 Jul 2007, Thomas Schwinge wrote:
> > Calling access(p, m) with p == NULL is not specified, so don't do that.  On
> > GNU/Hurd systems doing so will result in a SIGSEGV.
> > 
> > Signed-off-by: Thomas Schwinge <tschwinge@gnu.org>
> > ---
> 
> Isn't this the same patch as you sent before?

As I wrote in <20070728182542.GA22651@fencepost.gnu.org>: ``I noticed
that the patch I sent was prepared for an old version of the file.  I'll
send an updated patch that applies to the current revision.''

> > +		if (excludes_file != NULL && !access(excludes_file, R_OK))
> 
> We usually omit the "!= NULL"; see the other source code in git.git.

Okay, so I should sent a thusly modified version to get it applied?


Regards,
 Thomas

```

## Johannes Schindelin, 2007-07-28 20:16

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <Pine.LNX.4.64.0707282115450.14781@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0707282115450.14781%40racer.site
In-Reply-To: <20070728193402.GE23337@cip.informatik.uni-erlangen.de>

```
Hi,

On Sat, 28 Jul 2007, Thomas Glanzmann wrote:

> > Isn't this the same patch as you sent before?
> 
> > > @@ -74,7 +74,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec)
> > > @@ -60,7 +60,7 @@ static void fill_directory(struct dir_struct *dir, const char **pathspec,
>        ~~~~~ ~~~~~                                                                            ~
> 
> The offset of the diff has changed. Not that git couldn't sort it out by
> itself. And the function had one or more parameters less.

Ah.  Thanks for the explanation.

Ciao,
Dscho

```

## Johannes Schindelin, 2007-07-28 20:17

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <Pine.LNX.4.64.0707282116390.14781@racer.site>
URL: https://gitlist.dev/e/Pine.LNX.4.64.0707282116390.14781%40racer.site
In-Reply-To: <20070728194306.GA32203@fencepost.gnu.org>

```
Hi,

On Sat, 28 Jul 2007, Thomas Schwinge wrote:

> On Sat, Jul 28, 2007 at 08:30:07PM +0100, Johannes Schindelin wrote:
> > On Sat, 28 Jul 2007, Thomas Schwinge wrote:
> > > Calling access(p, m) with p == NULL is not specified, so don't do that.  On
> > > GNU/Hurd systems doing so will result in a SIGSEGV.
> > > 
> > > Signed-off-by: Thomas Schwinge <tschwinge@gnu.org>
> > > ---
> > 
> > Isn't this the same patch as you sent before?
> 
> As I wrote in <20070728182542.GA22651@fencepost.gnu.org>: ``I noticed
> that the patch I sent was prepared for an old version of the file.  I'll
> send an updated patch that applies to the current revision.''

Ah.

> > > +		if (excludes_file != NULL && !access(excludes_file, R_OK))
> > 
> > We usually omit the "!= NULL"; see the other source code in git.git.
> 
> Okay, so I should sent a thusly modified version to get it applied?

I don't think that is necessary; a small change like this is usually fixed 
by Junio with --amend.

Ciao,
Dscho

```

## Thomas Glanzmann, 2007-07-28 20:20

Subject: Re: [PATCH] Don't rely on unspecified behavior
Message-ID: <20070728202054.GA3616@cip.informatik.uni-erlangen.de>
URL: https://gitlist.dev/e/20070728202054.GA3616%40cip.informatik.uni-erlangen.de
In-Reply-To: <Pine.LNX.4.64.0707282115450.14781@racer.site>

```
Hello,

> Ah.  Thanks for the explanation.

I have operating system / real time systems exam on monday. I have to
prepare myself in stating the obvious.

	Thomas

```
