diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2007-04-30 09:27:23 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2007-04-30 09:27:23 +0000 |
commit | 5f13656d7f8529fa8989aef2351fef9e7f43857d (patch) | |
tree | 6c99c8dcbde83db11a7333a1976fe1d2ebd1c126 | |
parent | 4b635e7f91d0192dbb811986ae1f4eabffc43f76 (diff) | |
download | zsh-5f13656d7f8529fa8989aef2351fef9e7f43857d.tar.gz zsh-5f13656d7f8529fa8989aef2351fef9e7f43857d.tar.xz zsh-5f13656d7f8529fa8989aef2351fef9e7f43857d.zip |
23339: make malloc(0) allocate a byte
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | Src/mem.c | 18 |
2 files changed, 22 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog index 82630e530..c581b8679 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-04-30 Peter Stephenson <pws@csr.com> + + * 23339: Src/mem.c: make malloc(0) allocate a single byte + instead of returning invalid (and unfreeable) memory. + 2007-04-27 Peter Stephenson <pws@csr.com> * 23337: Src/Zle/compctl.c: argument to stat() wasn't diff --git a/Src/mem.c b/Src/mem.c index afc008cd7..448c4aad9 100644 --- a/Src/mem.c +++ b/Src/mem.c @@ -830,10 +830,26 @@ malloc(MALLOC_ARG_T size) #endif /* some systems want malloc to return the highest valid address plus one - if it is called with an argument of zero */ + if it is called with an argument of zero. + + TODO: really? Suppose we allocate more memory, so + that this is now in bounds, then a more rational application + that thinks it can free() anything it malloc'ed, even + of zero length, calls free for it? Aren't we in big + trouble? Wouldn't it be safer just to allocate some + memory anyway? + + If the above comment is really correct, then at least + we need to check in free() if we're freeing memory + at m_high. + */ if (!size) +#if 1 + size = 1; +#else return (MALLOC_RET_T) m_high; +#endif queue_signals(); /* just queue signals rather than handling them */ |