Re: [PATCH 20/21] fdopendir: port to OS/2 kLIBC

2014-12-05 Thread KO Myung-Hun


KO Myung-Hun wrote:
> 
> 
> Paul Eggert wrote:
>> KO Myung-Hun wrote:
>>> I want to do later separately. No ?
>>
>> You could put it in a later patch, I suppose, but I wouldn't want to
>> install this patch without also installing the later patch.
> 
> Ok. I'll try later.
> 

Done. Review, please...

-- 
KO Myung-Hun

Using Mozilla SeaMonkey 2.7.2
Under OS/2 Warp 4 for Korean with FixPak #15
In VirtualBox v4.1.32 on Intel Core i7-3615QM 2.30GHz with 8GB RAM

Korean OS/2 User Community : http://www.ecomstation.co.kr

From 262a473f232c1565ff8c84dae94a9b8ef958a941 Mon Sep 17 00:00:00 2001
From: KO Myung-Hun 
Date: Fri, 28 Nov 2014 16:47:12 +0900
Subject: [PATCH] opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC

* lib/closedir.c (closedir): Unregister fd if closedir() succeeds.
* lib/dirent.h.in (_gl_register_dirp_fd, _gl_unregister_dirp_fd):
Declare on kLIBC.
* lib/dirfd.c (struct dirp_fd_list): New. Structures to keep track of
fd associated with dirp.
(_gl_register_dirp_fd): New. Register fd associated with dirp to
dirp_fd_list.
(_gl_unregister_dirp_fd): New. Unregister fd with closing it.
(dirfd): Implemented for kLIBC.
* lib/fdopendir.c (fdopendir): Implemented for kLIBC.
* lib/opendir.c (opendir): New. Register fd and dirp pair if open()
succeeds.
* m4/closedir.m4 (gl_FUNC_CLOSEDIR): Check OS/2 as well.
* m4/dirfd.m4 (gl_FUNC_DIRFD): Likewise.
* m4/opendir.m4 (gl_FUNC_OPENDIR): Likewise.
* modules/closedir (Depends-on): Add dirfd.
* modules/dirfd (Depends-on): Add 'test $REPLACE_DIRFD = 1' to errno
condition.
(configure.ac): Add dirfd to LIBOBJS if $REPLACE_DIRFD = 1 as well.
* modules/fdopendir (Depends-on): Add dirfd.
* modules/opendir (Depends-on): Add dirfd.
---
 lib/closedir.c|  6 -
 lib/dirent.in.h   |  7 ++
 lib/dirfd.c   | 68 +++
 lib/fdopendir.c   | 36 +
 lib/opendir.c | 21 +
 m4/closedir.m4|  2 +-
 m4/dirfd.m4   |  3 ++-
 m4/opendir.m4 |  2 +-
 modules/closedir  |  1 +
 modules/dirfd |  5 ++--
 modules/fdopendir |  1 +
 modules/opendir   |  1 +
 12 files changed, 147 insertions(+), 6 deletions(-)

diff --git a/lib/closedir.c b/lib/closedir.c
index 940c6f9..b40181c 100644
--- a/lib/closedir.c
+++ b/lib/closedir.c
@@ -39,7 +39,7 @@
 int
 closedir (DIR *dirp)
 {
-# if REPLACE_FCHDIR
+# if REPLACE_FCHDIR || defined __KLIBC__
   int fd = dirfd (dirp);
 # endif
   int retval;
@@ -49,6 +49,10 @@ closedir (DIR *dirp)
 
   retval = closedir (dirp);
 
+# ifdef __KLIBC__
+  if (!retval)
+_gl_unregister_dirp_fd (fd);
+# endif
 #else
 
   if (dirp->current != INVALID_HANDLE_VALUE)
diff --git a/lib/dirent.in.h b/lib/dirent.in.h
index 4822d6b..cce86d9 100644
--- a/lib/dirent.in.h
+++ b/lib/dirent.in.h
@@ -156,6 +156,13 @@ _GL_WARN_ON_USE (closedir, "closedir is not portable - "
 #  endif
 _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1)));
 _GL_CXXALIAS_RPL (dirfd, int, (DIR *));
+
+#  ifdef __KLIBC__
+/* Gnulib internal hooks needed to maintain the dirfd metadata.  */
+_GL_EXTERN_C int _gl_register_dirp_fd (int fd, DIR *dirp)
+ _GL_ARG_NONNULL ((2));
+_GL_EXTERN_C void _gl_unregister_dirp_fd (int fd);
+#  endif
 # else
 #  if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd
 /* dirfd is defined as a macro and not as a function.
diff --git a/lib/dirfd.c b/lib/dirfd.c
index 4d37928..aa6514f 100644
--- a/lib/dirfd.c
+++ b/lib/dirfd.c
@@ -22,11 +22,79 @@
 #include 
 #include 
 
+#ifdef __KLIBC__
+# include 
+# include 
+
+static struct dirp_fd_list
+{
+  DIR *dirp;
+  int fd;
+  struct dirp_fd_list *next;
+} *dirp_fd_start = NULL;
+
+/* Register fd associated with dirp to dirp_fd_list. */
+int
+_gl_register_dirp_fd (int fd, DIR *dirp)
+{
+  struct dirp_fd_list *new_dirp_fd;
+
+  new_dirp_fd = malloc (sizeof (*new_dirp_fd));
+  if (!new_dirp_fd)
+return -1;
+
+  new_dirp_fd->dirp = dirp;
+  new_dirp_fd->fd = fd;
+  new_dirp_fd->next = dirp_fd_start;
+
+  dirp_fd_start = new_dirp_fd;
+
+  return 0;
+}
+
+/* Unregister fd from dirp_fd_list with closing it */
+void
+_gl_unregister_dirp_fd (int fd)
+{
+  struct dirp_fd_list *dirp_fd;
+  struct dirp_fd_list *dirp_fd_prev;
+
+  for (dirp_fd_prev = NULL, dirp_fd = dirp_fd_start; dirp_fd;
+   dirp_fd_prev = dirp_fd, dirp_fd = dirp_fd->next)
+{
+  if (dirp_fd->fd == fd)
+{
+  if (dirp_fd_prev)
+dirp_fd_prev->next = dirp_fd->next;
+  else  /* dirp_fd == dirp_fd_start */
+dirp_fd_start = dirp_fd_start->next;
+
+  close (fd);
+  free (dirp_fd);
+  break;
+}
+}
+}
+#endif
+
 int
 dirfd (DIR *dir_p)
 {
   int fd = DIR_TO_FD (dir_p);
   if (fd == -1)
+#ifndef __KLIBC__
 errno = ENOTSUP;
+#else
+{
+  struct dirp_fd_list *dirp_fd;
+
+  for (dirp_fd = dirp_fd_start; dirp_fd; dirp_fd = dirp_fd->next)
+if (dirp_fd->dirp == dir_p)
+  return dirp_fd->fd;
+
+  errno = EINVAL;
+

Re: [PATCH 15/21] freopen: workaround freopen() on OS/2 kLIBC

2014-12-05 Thread Bruno Haible
KO Myung-Hun wrote:
> I also don't want to break the convention.
> 
> Fixed.

Thanks. This looks perfect now.

Bruno




Re: [PATCH] printf: fix configure check on big endian systems

2014-12-05 Thread Bruno Haible
Pádraig Brady wrote on 2014-11-27:
> + printf: fix configure check on big endian systems
> + * m4/printf.m4 (gl_PRINTF_INFINITE_LONG_DOUBLE): Add missing bracket.

The same typo occurs in a few other places as well. I'm fixing them in the
same way.


2014-12-05  Bruno Haible  

Fix LDBL80_WORDS macro on big endian platforms.
* m4/isfinite.m4 (gl_ISFINITEL_WORKS): Add missing parenthesis in
LDBL80_WORDS macro.
* m4/isinf.m4 (gl_ISINFL_WORKS): Likewise.
* m4/isnanl.m4 (gl_FUNC_ISNANL_WORKS): Likewise.
* tests/test-isfinite.c (test_isfinitel): Likewise.
* tests/test-isinf.c (test_isinfl): Likewise.
* tests/test-isnan.c (test_long_double): Likewise.
* tests/test-isnanl.h (main): Likewise.
* tests/test-snprintf-posix.h (LDBL80_WORDS): Add missing parenthesis.
* tests/test-sprintf-posix.h (LDBL80_WORDS): Likewise.
* tests/test-vasnprintf-posix.c (LDBL80_WORDS): Likewise.
* tests/test-vasprintf-posix.c (LDBL80_WORDS): Likewise.
Reported by Pádraig Brady.

diff --git a/ChangeLog b/ChangeLog
index 7379fa6..fb6723b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2014-12-05  Bruno Haible  
+
+   Fix LDBL80_WORDS macro on big endian platforms.
+   * m4/isfinite.m4 (gl_ISFINITEL_WORKS): Add missing parenthesis in
+   LDBL80_WORDS macro.
+   * m4/isinf.m4 (gl_ISINFL_WORKS): Likewise.
+   * m4/isnanl.m4 (gl_FUNC_ISNANL_WORKS): Likewise.
+   * tests/test-isfinite.c (test_isfinitel): Likewise.
+   * tests/test-isinf.c (test_isinfl): Likewise.
+   * tests/test-isnan.c (test_long_double): Likewise.
+   * tests/test-isnanl.h (main): Likewise.
+   * tests/test-snprintf-posix.h (LDBL80_WORDS): Add missing parenthesis.
+   * tests/test-sprintf-posix.h (LDBL80_WORDS): Likewise.
+   * tests/test-vasnprintf-posix.c (LDBL80_WORDS): Likewise.
+   * tests/test-vasprintf-posix.c (LDBL80_WORDS): Likewise.
+   Reported by Pádraig Brady.
+
 2014-12-02  KO Myung-Hun  
 
git-version-gen: do not print new line characters
diff --git a/m4/isfinite.m4 b/m4/isfinite.m4
index 53ad909..bfd1ea3 100644
--- a/m4/isfinite.m4
+++ b/m4/isfinite.m4
@@ -1,4 +1,4 @@
-# isfinite.m4 serial 13
+# isfinite.m4 serial 14
 dnl Copyright (C) 2007-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -94,7 +94,7 @@ int main ()
 # ifdef WORDS_BIGENDIAN
 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
  { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
-   ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),\
+   ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
(unsigned int) (mantlo) << 16\
  }
 # else
diff --git a/m4/isinf.m4 b/m4/isinf.m4
index 7174ace..4d844b0 100644
--- a/m4/isinf.m4
+++ b/m4/isinf.m4
@@ -1,4 +1,4 @@
-# isinf.m4 serial 9
+# isinf.m4 serial 10
 dnl Copyright (C) 2007-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -101,7 +101,7 @@ int main ()
 # ifdef WORDS_BIGENDIAN
 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
  { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
-   ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),\
+   ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
(unsigned int) (mantlo) << 16\
  }
 # else
diff --git a/m4/isnanl.m4 b/m4/isnanl.m4
index 98b2b69..a26cc93 100644
--- a/m4/isnanl.m4
+++ b/m4/isnanl.m4
@@ -1,4 +1,4 @@
-# isnanl.m4 serial 17
+# isnanl.m4 serial 18
 dnl Copyright (C) 2007-2014 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -177,7 +177,7 @@ int main ()
 # ifdef WORDS_BIGENDIAN
 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
  { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
-   ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),\
+   ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
(unsigned int) (mantlo) << 16\
  }
 # else
diff --git a/tests/test-isfinite.c b/tests/test-isfinite.c
index 5d320ea..5b3f1dd 100644
--- a/tests/test-isfinite.c
+++ b/tests/test-isfinite.c
@@ -181,7 +181,7 @@ test_isfinitel ()
 # ifdef WORDS_BIGENDIAN
 #  define LDBL80_WORDS(exponent,manthi,mantlo) \
  { ((unsigned int) (exponent) << 16) | ((unsigned int) (manthi) >> 16), \
-   ((unsigned int) (manthi) << 16) | (unsigned int) (mantlo) >> 16),\
+   ((unsigned int) (manthi) << 16) | ((unsigned int) (mantlo) >> 16),   \
   

[PATCH] filevercmp, posixtm: avoid compiler warnings with -O3

2014-12-05 Thread Pádraig Brady
* lib/filevercmp.h (filevercmp): Tag with _GL_ATTRIBUTE_PURE
* lib/posixtm.c: (IF_LINT): Define.
(posix_time_parse): Use it to void a "may be used uninitialized"
warning, seen only with -O3.
---
 lib/filevercmp.h | 2 +-
 lib/posixtm.c| 9 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/filevercmp.h b/lib/filevercmp.h
index 72785cd..ad359eb 100644
--- a/lib/filevercmp.h
+++ b/lib/filevercmp.h
@@ -37,6 +37,6 @@
PREFIX VER2 SUFFIX) < 0.
 
This function is intended to be a replacement for strverscmp. */
-int filevercmp (const char *s1, const char *s2);
+int filevercmp (const char *s1, const char *s2) _GL_ATTRIBUTE_PURE;
 
 #endif /* FILEVERCMP_H */
diff --git a/lib/posixtm.c b/lib/posixtm.c
index 2fe81ab..3023932 100644
--- a/lib/posixtm.c
+++ b/lib/posixtm.c
@@ -27,6 +27,13 @@
 #include 
 #include 
 
+/* Use this to suppress gcc's "...may be used uninitialized" warnings. */
+#ifdef lint
+# define IF_LINT(Code) Code
+#else
+# define IF_LINT(Code) /* empty */
+#endif
+
 #if USE_UNLOCKED_IO
 # include "unlocked-io.h"
 #endif
@@ -118,6 +125,8 @@ posix_time_parse (struct tm *tm, const char *s, unsigned 
int syntax_bits)
   if (len != 8 && len != 10 && len != 12)
 return 1;
 
+  IF_LINT(if (len < 8) return 1;)
+
   if (dot)
 {
   if (!(syntax_bits & PDS_SECONDS))
-- 
2.1.0




Re: ARGP: Documentation of

2014-12-05 Thread Robert Hairgrove
Robert Hairgrove  roberthairgrove.com> writes:
> Robert Hairgrove  roberthairgrove.com> writes:
> > I am writing some little C++ wrapper classes for the argp functions.
...

One more question:
If argp_parse calls exit() and terminates the program, will the destructors
of my C++ objects be called?

Thank you.




Re: "test-lock" stuck on FreeBSD

2014-12-05 Thread Ed Maste
On 4 December 2014 at 21:33, Daiki Ueno  wrote:
> Ed Maste  writes:
>
>> OK, I can reproduce it in a single-vCPU bhyve VM (the default is 2).
>> Do you mind checking if it's no longer reproducible in KVM with 2 or
>> more vCPUs?
>
> Thanks, it indeed seems to fix the issue:

Thanks for confirming.

Upon further investigation this issue is fixed already in FreeBSD
10.1; further details are in FreeBSD PR 195098[1] for anyone
interested.

Hopefully we can get a 10.1 VM image for the pretest site - I'm happy
to help if needed.

[1] https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=195098



Re: [PATCH] printf: fix configure check on big endian systems

2014-12-05 Thread Jim Meyering
On Fri, Dec 5, 2014 at 2:37 AM, Bruno Haible  wrote:
> Pádraig Brady wrote on 2014-11-27:
>> + printf: fix configure check on big endian systems
>> + * m4/printf.m4 (gl_PRINTF_INFINITE_LONG_DOUBLE): Add missing bracket.
>
> The same typo occurs in a few other places as well. I'm fixing them in the
> same way.
>
>
> 2014-12-05  Bruno Haible  
>
> Fix LDBL80_WORDS macro on big endian platforms.
> * m4/isfinite.m4 (gl_ISFINITEL_WORKS): Add missing parenthesis in
> LDBL80_WORDS macro.
> * m4/isinf.m4 (gl_ISINFL_WORKS): Likewise.
> * m4/isnanl.m4 (gl_FUNC_ISNANL_WORKS): Likewise.
> * tests/test-isfinite.c (test_isfinitel): Likewise.
> * tests/test-isinf.c (test_isinfl): Likewise.
> * tests/test-isnan.c (test_long_double): Likewise.
> * tests/test-isnanl.h (main): Likewise.
> * tests/test-snprintf-posix.h (LDBL80_WORDS): Add missing parenthesis.
> * tests/test-sprintf-posix.h (LDBL80_WORDS): Likewise.
> * tests/test-vasnprintf-posix.c (LDBL80_WORDS): Likewise.
> * tests/test-vasprintf-posix.c (LDBL80_WORDS): Likewise.
> Reported by Pádraig Brady.

Very nice!



Re: ARGP: Documentation of

2014-12-05 Thread Robert Hairgrove
Robert Hairgrove  roberthairgrove.com> writes:
> If argp_parse calls exit() and terminates the program, will the destructors
> of my C++ objects be called?

Silly question ... now I realize that they won't be called unless I take
appropriate precautions, such as keeping a global vector of unique_ptr's or
something along those lines.




recent changes to obstacks cause many out of memory failures in M4 master testsuite

2014-12-05 Thread Gary V. Vaughan
Hi,

To pick up bug fixes in maint.mk required for 'make public-submodule-commit' 
and dependers to work on Mac OS X 10.10, I just tried to update GNU M4's master 
branch to gnulib master HEAD, but that causes a raft of test failures where m4 
bails out with a 'memory exhausted' error before completing the tests.

Bisecting my way to the the first gnulib changeset that causes these failures, 
I landed at:

  bb2ab7e 2014-10-29 14:02 Alan Modra   obstack: 64-bit obstack support, part 2

Which is not surprising as GNU M4 uses GNU obstack extensively throughout.  Any 
revisions prior to that allow m4 to pass it's tests, but I'm afraid I don't 
understand the change well enough to point at the actual root of the issue.  
Hopefully someone here more knowledgable than I will be able to advise.

Cheers,
-- 
Gary V. Vaughan (gary AT gnu DOT org)





Re: recent changes to obstacks cause many out of memory failures in M4 master testsuite

2014-12-05 Thread Eric Blake
On 12/05/2014 12:03 PM, Gary V. Vaughan wrote:

> Bisecting my way to the the first gnulib changeset that causes these 
> failures, I landed at:
> 
>   bb2ab7e 2014-10-29 14:02 Alan Modra   obstack: 64-bit obstack support, part 
> 2
> 
> Which is not surprising as GNU M4 uses GNU obstack extensively throughout.

I bet it has to do with this:

src/builtin.c:  obstack_blank (data->obs, sizeof (symbol *));
src/builtin.c:  obstack_blank_fast (obs, len);
src/builtin.c:  obstack_blank (obs, -1);
src/macro.c:   obstack_blank is documented to take a negative size to
reduce the
src/macro.c:  obstack_blank (&argv_stack, -argc * sizeof (token_data *));

vs. the discussion on gnulib that we intentionally changed upstream
obstack_blank to no longer do this, and that you HAVE to use
obstack_blank_fast to get that effect.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [PATCH 0/5] obstacks again

2014-12-05 Thread Eric Blake
On 10/29/2014 09:35 PM, Paul Eggert wrote:
> Alan Modra wrote:
> 
>> One thing though, I didn't put the ChangeLog diffs in the patch as I
>> usually add them when committing.
> 
> Oh, I missed that.  I added them now.  For Gnulib it's better to put
> them into the patch.
> 
>> It is no longer possible to shrink an obstack with obstack_blank (but
>> you can still do that with obstack_blank_fast).
> 
> Ouch, I hadn't noticed that.  That's an incompatible change and I expect
> it will break real-world usage for no particularly good reason, so we
> really need to fix this.  How about making the 2nd argument to
> obstack_blank and obstack_blank_fast be of type ptrdiff_t rather than
> size_t?

It breaks GNU M4, for a starter :)  But at least we predicted that it
would happen, and I'm hoping the fallback of obstack_blank_fast does the
job.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: recent changes to obstacks cause many out of memory failures in M4 master testsuite

2014-12-05 Thread Gary V . Vaughan
Hi Eric,

> On Dec 5, 2014, at 7:11 PM, Eric Blake  wrote:
> 
> On 12/05/2014 12:03 PM, Gary V. Vaughan wrote:
> 
>> Bisecting my way to the the first gnulib changeset that causes these 
>> failures, I landed at:
>> 
>>  bb2ab7e 2014-10-29 14:02 Alan Modra   obstack: 64-bit obstack support, part 
>> 2
>> 
>> Which is not surprising as GNU M4 uses GNU obstack extensively throughout.
> 
> I bet it has to do with this:
> 
> src/builtin.c:  obstack_blank (data->obs, sizeof (symbol *));
> src/builtin.c:  obstack_blank_fast (obs, len);
> src/builtin.c:  obstack_blank (obs, -1);
> src/macro.c:   obstack_blank is documented to take a negative size to
> reduce the
> src/macro.c:  obstack_blank (&argv_stack, -argc * sizeof (token_data *));

ACK.  Only, on master I get:

$ grep obstack_blank `git ls-files`
grep: build-aux/gnulib: Is a directory
m4/macro.c:  obstack_blank (&context->trace_messages, start - len);
modules/gnu.c:  obstack_blank_fast (obs, len);
modules/m4.c:  obstack_blank (symbol_data->obs, sizeof *symbol_data->base);
modules/m4.c:  obstack_blank_fast (symbol_data->obs, sizeof 
*symbol_data->base);
modules/m4.c:  obstack_blank (obs, -1);
modules/m4.c:  obstack_blank (obs, min - uvalue);
modules/m4.c:  obstack_blank (obs, uvalue);
modules/m4.c:  obstack_blank (obs, min);

Changing just the call in macro.c to obstack_blank_fast does indeed allow the 
tests
to pass again.  For correctness, I'll also change the `obstack_blank (obs, -1)` 
call,
and audit the other call sites for possible changes along the same lines.

> vs. the discussion on gnulib that we intentionally changed upstream
> obstack_blank to no longer do this, and that you HAVE to use
> obstack_blank_fast to get that effect.

Bah, I didn't notice the nuances of that conversation at the time :-(  Thanks 
for the
pointer.

Cheers,
-- 
Gary V. Vaughan (gary AT gnu DOT org)


Re: [PATCH 0/5] obstacks again

2014-12-05 Thread Gary V. Vaughan
On Dec 5, 2014, at 7:13 PM, Eric Blake  wrote:
> On 10/29/2014 09:35 PM, Paul Eggert wrote:
>> Alan Modra wrote:
>> 
>>> One thing though, I didn't put the ChangeLog diffs in the patch as I
>>> usually add them when committing.
>> 
>> Oh, I missed that.  I added them now.  For Gnulib it's better to put
>> them into the patch.
>> 
>>> It is no longer possible to shrink an obstack with obstack_blank (but
>>> you can still do that with obstack_blank_fast).
>> 
>> Ouch, I hadn't noticed that.  That's an incompatible change and I expect
>> it will break real-world usage for no particularly good reason, so we
>> really need to fix this.  How about making the 2nd argument to
>> obstack_blank and obstack_blank_fast be of type ptrdiff_t rather than
>> size_t?
> 
> It breaks GNU M4, for a starter :)  But at least we predicted that it
> would happen, and I'm hoping the fallback of obstack_blank_fast does the
> job.

It does, thanks.

Although for someone not following bug-gnulib fairly carefully, it is far
from obvious why bumping gnulib makes your application suddenly use up all
the available memory.  Which is a shame, because, other than that M4 would
have been perfectly functional after the gnulib bump without any special
client code changes.

If there's a way to at least diagnose negative arguments rather than silently
change behavior, that would save other projects some migration headaches...

Cheers,
-- 
Gary V. Vaughan (gary AT gnu DOT org)



[PATCH] vasnprintf: fix potential use after free

2014-12-05 Thread Pádraig Brady
* lib/vasnprintf.c (VASNPRINTF): Fix free-memory read,
flagged by clang-analyzer 3.4.2.
---
 ChangeLog| 6 ++
 lib/vasnprintf.c | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 1c4a7ab..41207ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-12-06  Pádraig Brady  
+
+   vasnprintf: fix potential use after free
+   * lib/vasnprintf.c (VASNPRINTF): Fix free-memory read,
+   flagged by clang-analyzer 3.4.2.
+
 2014-12-05  Pádraig Brady  
 
filevercmp, posixtm: avoid compiler warnings with -O3
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 0484c4e..223be07 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -5184,13 +5184,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
   free (result);
 if (buf_malloced != NULL)
   free (buf_malloced);
-CLEANUP ();
 errno =
   (saved_errno != 0
? saved_errno
: (dp->conversion == 'c' || dp->conversion == 's'
   ? EILSEQ
   : EINVAL));
+CLEANUP ();
 return NULL;
   }
 
-- 
2.1.0




[PATCH] apply _GL_ATTRIBUTE_PURE to some inline functions

2014-12-05 Thread Pádraig Brady
clang 3.4.2 flagged these inline functions as pure

* lib/savewd.h (savewd_errno): Set _GL_ATTRIBUTE_PURE.
* lib/sig-handler.h (get_handler): Likewise.
* lib/stat-time.h (get_stat_{a,c,m,birth}time{,_ns}): Likewise.
* lib/timespec.h (timespec_cmp, timespec_sign): Likewize.
---
 lib/savewd.h  |  2 +-
 lib/sig-handler.h |  2 +-
 lib/stat-time.h   | 16 
 lib/timespec.h|  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/savewd.h b/lib/savewd.h
index cd0817b..4d2d7d6 100644
--- a/lib/savewd.h
+++ b/lib/savewd.h
@@ -125,7 +125,7 @@ int savewd_chdir (struct savewd *wd, char const *dir, int 
options,
 int savewd_restore (struct savewd *wd, int status);
 
 /* Return WD's error number, or 0 if WD is not in an error state.  */
-SAVEWD_INLINE int
+SAVEWD_INLINE int _GL_ATTRIBUTE_PURE
 savewd_errno (struct savewd const *wd)
 {
   return (wd->state == ERROR_STATE ? wd->val.errnum : 0);
diff --git a/lib/sig-handler.h b/lib/sig-handler.h
index f4fe7ec..3af1a91 100644
--- a/lib/sig-handler.h
+++ b/lib/sig-handler.h
@@ -34,7 +34,7 @@ typedef void (*sa_handler_t) (int);
 /* Return the handler of a signal, as a sa_handler_t value regardless
of its true type.  The resulting function can be compared to
special values like SIG_IGN but it is not portable to call it.  */
-SIG_HANDLER_INLINE sa_handler_t
+SIG_HANDLER_INLINE sa_handler_t _GL_ATTRIBUTE_PURE
 get_handler (struct sigaction const *a)
 {
 #ifdef SA_SIGINFO
diff --git a/lib/stat-time.h b/lib/stat-time.h
index b3df6eb..9cbf8e0 100644
--- a/lib/stat-time.h
+++ b/lib/stat-time.h
@@ -54,7 +54,7 @@ _GL_INLINE_HEADER_BEGIN
 #endif
 
 /* Return the nanosecond component of *ST's access time.  */
-_GL_STAT_TIME_INLINE long int
+_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
 get_stat_atime_ns (struct stat const *st)
 {
 # if defined STAT_TIMESPEC
@@ -67,7 +67,7 @@ get_stat_atime_ns (struct stat const *st)
 }
 
 /* Return the nanosecond component of *ST's status change time.  */
-_GL_STAT_TIME_INLINE long int
+_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
 get_stat_ctime_ns (struct stat const *st)
 {
 # if defined STAT_TIMESPEC
@@ -80,7 +80,7 @@ get_stat_ctime_ns (struct stat const *st)
 }
 
 /* Return the nanosecond component of *ST's data modification time.  */
-_GL_STAT_TIME_INLINE long int
+_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
 get_stat_mtime_ns (struct stat const *st)
 {
 # if defined STAT_TIMESPEC
@@ -93,7 +93,7 @@ get_stat_mtime_ns (struct stat const *st)
 }
 
 /* Return the nanosecond component of *ST's birth time.  */
-_GL_STAT_TIME_INLINE long int
+_GL_STAT_TIME_INLINE long int _GL_ATTRIBUTE_PURE
 get_stat_birthtime_ns (struct stat const *st)
 {
 # if defined HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC_TV_NSEC
@@ -108,7 +108,7 @@ get_stat_birthtime_ns (struct stat const *st)
 }
 
 /* Return *ST's access time.  */
-_GL_STAT_TIME_INLINE struct timespec
+_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
 get_stat_atime (struct stat const *st)
 {
 #ifdef STAT_TIMESPEC
@@ -122,7 +122,7 @@ get_stat_atime (struct stat const *st)
 }
 
 /* Return *ST's status change time.  */
-_GL_STAT_TIME_INLINE struct timespec
+_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
 get_stat_ctime (struct stat const *st)
 {
 #ifdef STAT_TIMESPEC
@@ -136,7 +136,7 @@ get_stat_ctime (struct stat const *st)
 }
 
 /* Return *ST's data modification time.  */
-_GL_STAT_TIME_INLINE struct timespec
+_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
 get_stat_mtime (struct stat const *st)
 {
 #ifdef STAT_TIMESPEC
@@ -151,7 +151,7 @@ get_stat_mtime (struct stat const *st)
 
 /* Return *ST's birth time, if available; otherwise return a value
with tv_sec and tv_nsec both equal to -1.  */
-_GL_STAT_TIME_INLINE struct timespec
+_GL_STAT_TIME_INLINE struct timespec _GL_ATTRIBUTE_PURE
 get_stat_birthtime (struct stat const *st)
 {
   struct timespec t;
diff --git a/lib/timespec.h b/lib/timespec.h
index 872cbb7..dfc1277 100644
--- a/lib/timespec.h
+++ b/lib/timespec.h
@@ -74,7 +74,7 @@ make_timespec (time_t s, long int ns)
 
The (int) cast avoids a gcc -Wconversion warning.  */
 
-_GL_TIMESPEC_INLINE int
+_GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE
 timespec_cmp (struct timespec a, struct timespec b)
 {
   return (a.tv_sec < b.tv_sec ? -1
@@ -84,7 +84,7 @@ timespec_cmp (struct timespec a, struct timespec b)
 
 /* Return -1, 0, 1, depending on the sign of A.  A.tv_nsec must be
nonnegative.  */
-_GL_TIMESPEC_INLINE int
+_GL_TIMESPEC_INLINE int _GL_ATTRIBUTE_PURE
 timespec_sign (struct timespec a)
 {
   return a.tv_sec < 0 ? -1 : a.tv_sec || a.tv_nsec;
-- 
2.1.0




Re: [PATCH 0/5] obstacks again

2014-12-05 Thread Alan Modra
On Fri, Dec 05, 2014 at 09:02:46PM +, Gary V. Vaughan wrote:
> If there's a way to at least diagnose negative arguments rather than silently
> change behavior, that would save other projects some migration headaches...

We could diagnose one of the m4 uses of obstack_blank at compile time,
but not the one in m4/macro.c:trace_flush which has a non-constant
shrink value..

Yes, I agree this can cause some pain, but at least dying with
out-of-memory is a loud symptom.

The alternative is to do as Paul suggested and make obstack_blank
accept a negative length argument, but that would
- kill >2G obstacks on 32-bit targets,
- lose the nice symmetry with other obstack functions,
and obstack_blank_fast is the right interface to use for shrinking.

-- 
Alan Modra
Australia Development Lab, IBM



Re: [PATCH] vasnprintf: fix potential use after free

2014-12-05 Thread Eric Blake
On 12/05/2014 06:23 PM, Pádraig Brady wrote:
> * lib/vasnprintf.c (VASNPRINTF): Fix free-memory read,
> flagged by clang-analyzer 3.4.2.
> ---
>  ChangeLog| 6 ++
>  lib/vasnprintf.c | 2 +-
>  2 files changed, 7 insertions(+), 1 deletion(-)
> 

> +++ b/lib/vasnprintf.c
> @@ -5184,13 +5184,13 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
>free (result);
>  if (buf_malloced != NULL)
>free (buf_malloced);
> -CLEANUP ();
>  errno =
>(saved_errno != 0
> ? saved_errno
> : (dp->conversion == 'c' || dp->conversion == 's'
>? EILSEQ
>: EINVAL));
> +CLEANUP ();

Ouch.  This is a bug.  The whole point of assigning to errno after
CLEANUP() is that CLEANUP() may invalidate the value stored in errno.

I suggest doing something like:

if (saved_errno == 0)
  saved_errno = dp->conversion == 'c' || dp->conversion == 's'
? EILSEQ : EINVAL;
CLEANUP();
errno = saved_errno;


-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature