From 19ab699100675970f3ba9536a23abe76e1baaffa Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 11 Feb 2016 19:00:50 +0000 Subject: [PATCH 1/7] fix working with ditroff on Schillix, confirmed by Jvrg --- mksh.1 | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/mksh.1 b/mksh.1 index 923c721..c6f9736 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.388 2016/01/20 22:04:54 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.389 2016/02/11 19:00:50 tg Exp $ .\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, @@ -29,7 +29,9 @@ .\" * ^ is size-reduced and placed atop in groff, so use \*(ha .\" * \(en does not work in nroff, so use \*(en .\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba -.\" Also make sure to use \& especially with two-letter words. +.\" Also make sure to use \& *before* a punctuation char that is to not +.\" be interpreted as punctuation, and especially with two-letter words +.\" but also (after) a period that does not end a sentence (“e.g.\&”). .\" The section after the "doc" macropackage has been loaded contains .\" additional code to convene between the UCB mdoc macropackage (and .\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage. @@ -74,7 +76,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: January 20 2016 $ +.Dd $Mdocdate: February 11 2016 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" @@ -431,7 +433,7 @@ statements; .Ql \&(( .. )) is used in arithmetic expressions; and lastly, -.Ql \&( .. )\& +.Ql \&( .. \&) is used to create subshells. .Pp Whitespace and meta-characters can be quoted individually using a backslash @@ -1943,7 +1945,7 @@ Time since the epoch, as returned by formatted as decimal .Va tv_sec followed by a dot -.Pq Sq .\& +.Pq Sq \&. and .Va tv_usec padded to exactly six decimal digits. @@ -3979,14 +3981,14 @@ becomes unusable, and directly calls .Pp .It Ic return Op Ar status Returns from a function or -.Ic .\& +.Ic \&. script, with exit status .Ar status . If no .Ar status is given, the exit status of the last executed command is used. If used outside of a function or -.Ic .\& +.Ic \&. script, it has the same effect as .Ic exit . Note that @@ -3994,9 +3996,9 @@ Note that treats both profile and .Ev ENV files as -.Ic .\& +.Ic \&. scripts, while the original Korn shell only treats profiles as -.Ic .\& +.Ic \&. scripts. .Pp .It Xo @@ -4074,7 +4076,7 @@ explicitly tested by a shell construct such as .Ic until , .Ic while , or -.Ic !\& +.Ic \&! statements. For .Ic && From af94276ea7f0560bc8e2587cac753f9650e47f7b Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 11 Feb 2016 20:12:09 +0000 Subject: [PATCH 2/7] =?UTF-8?q?merge=20most=20recent=20portmdoc=20into=20a?= =?UTF-8?q?=CC=B2l=CC=B2l=CC=B2=20of=20its=20users;=20fixup=20.\&=20into?= =?UTF-8?q?=20\&.=20like=20in=20mksh(1),=20for=20Schillix=20ditroff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lksh.1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lksh.1 b/lksh.1 index 8b26166..a1a8337 100644 --- a/lksh.1 +++ b/lksh.1 @@ -1,6 +1,6 @@ -.\" $MirOS: src/bin/mksh/lksh.1,v 1.16 2015/12/12 22:25:14 tg Exp $ +.\" $MirOS: src/bin/mksh/lksh.1,v 1.17 2016/02/11 20:12:09 tg Exp $ .\"- -.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015 +.\" Copyright (c) 2008, 2009, 2010, 2012, 2013, 2015, 2016 .\" mirabilos .\" .\" Provided that these terms and disclaimer and all copyright notices @@ -27,7 +27,9 @@ .\" * ^ is size-reduced and placed atop in groff, so use \*(ha .\" * \(en does not work in nroff, so use \*(en .\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba -.\" Also make sure to use \& especially with two-letter words. +.\" Also make sure to use \& *before* a punctuation char that is to not +.\" be interpreted as punctuation, and especially with two-letter words +.\" but also (after) a period that does not end a sentence (“e.g.\&”). .\" The section after the "doc" macropackage has been loaded contains .\" additional code to convene between the UCB mdoc macropackage (and .\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage. @@ -72,7 +74,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: December 12 2015 $ +.Dd $Mdocdate: February 11 2016 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" From 8e7abc48eb89d3bd31d644168251431dde6a4ce5 Mon Sep 17 00:00:00 2001 From: tg Date: Thu, 11 Feb 2016 20:19:44 +0000 Subject: [PATCH 3/7] =?UTF-8?q?head(1)=20is=20not=20portable=20(-n=201=20n?= =?UTF-8?q?ot=20pr=C3=A6-POSIX/ancient,=20-1=20not=20busybox)=20=E2=87=92?= =?UTF-8?q?=20use=20sed(1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug spotted by wbx@ --- check.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/check.t b/check.t index 7de6af9..4a4a228 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.722 2016/01/21 18:24:35 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.723 2016/02/11 20:19:44 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -12183,7 +12183,7 @@ stdin: Copyright (C) 2002 Free Software Foundation, Inc.' EOF chmod +x bash - "$__progname" -xc 'foo=$(./bash --version 2>&1 | head -1); echo "=$foo="' + "$__progname" -xc 'foo=$(./bash --version 2>&1 | sed 1q); echo "=$foo="' expected-stdout: =GNU bash, version 2.05b.0(1)-release (i386-ecce-mirbsd10)= expected-stderr-pattern: From f0a042f07036b7de747e17040e6b70feaf4738ad Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 24 Feb 2016 01:44:46 +0000 Subject: [PATCH 4/7] implement mmap-using mechanism to catch buffer underruns inside mksh (pulls stdio, is rather BSD-specific and memory-hungry and a bit slow) --- jobs.c | 6 ++--- lalloc.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++----- main.c | 5 ++++- sh.h | 25 ++++++++++++++++----- 4 files changed, 88 insertions(+), 16 deletions(-) diff --git a/jobs.c b/jobs.c index 6c2ca13..38e7b39 100644 --- a/jobs.c +++ b/jobs.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.118 2016/01/21 18:24:41 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.119 2016/02/24 01:44:45 tg Exp $"); #if HAVE_KILLPG #define mksh_killpg killpg @@ -45,8 +45,8 @@ struct proc { int state; int status; /* wait status */ /* process command string from vistree */ - char command[256 - (ALLOC_SIZE + sizeof(Proc *) + sizeof(pid_t) + - 2 * sizeof(int))]; + char command[256 - (ALLOC_OVERHEAD + sizeof(Proc *) + + sizeof(pid_t) + 2 * sizeof(int))]; }; /* Notify/print flag - j_print() argument */ diff --git a/lalloc.c b/lalloc.c index 4eca6a5..98aabde 100644 --- a/lalloc.c +++ b/lalloc.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009, 2010, 2011, 2013, 2014 + * Copyright (c) 2009, 2010, 2011, 2013, 2014, 2016 * mirabilos * * Provided that these terms and disclaimer and all copyright notices @@ -19,8 +19,11 @@ */ #include "sh.h" +#ifdef MKSH_ALLOC_CATCH_UNDERRUNS +#include +#endif -__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.23 2015/11/29 17:05:01 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.24 2016/02/24 01:44:46 tg Exp $"); /* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */ #if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0) @@ -29,13 +32,66 @@ __RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.23 2015/11/29 17:05:01 tg Exp $"); #define remalloc(p,n) realloc_osi((p), (n)) #endif -#define ALLOC_ISUNALIGNED(p) (((size_t)(p)) % ALLOC_SIZE) static ALLOC_ITEM *findptr(ALLOC_ITEM **, char *, Area *); +#ifndef MKSH_ALLOC_CATCH_UNDERRUNS +#define ALLOC_ISUNALIGNED(p) (((size_t)(p)) % ALLOC_SIZE) +#else +#define ALLOC_ISUNALIGNED(p) (((size_t)(p)) & 4095) +#undef remalloc +#undef free_osimalloc + +static void +free_osimalloc(void *ptr) +{ + struct lalloc *lp = ptr; + + if (munmap(lp, lp->len)) + err(1, "free_osimalloc"); +} + +static void * +remalloc(void *ptr, size_t size) +{ + struct lalloc *lp, *lold = ptr; + + size = (size + 4095) & ~(size_t)4095; + + if (lold && lold->len >= size) + return (ptr); + + if ((lp = mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, (off_t)0)) == MAP_FAILED) + err(1, "remalloc: mmap(%zu)", size); + if (ALLOC_ISUNALIGNED(lp)) + errx(1, "remalloc: unaligned(%p)", lp); + if (mprotect(((char *)lp) + 4096, 4096, PROT_NONE)) + err(1, "remalloc: mprotect"); + lp->len = size; + + if (lold) { + memcpy(((char *)lp) + 8192, ((char *)lold) + 8192, + lold->len - 8192); + if (munmap(lold, lold->len)) + err(1, "remalloc: munmap"); + } + + return (lp); +} +#endif + void ainit(Area *ap) { +#ifdef MKSH_ALLOC_CATCH_UNDERRUNS + if (sysconf(_SC_PAGESIZE) != 4096) { + fprintf(stderr, "mksh: fatal: pagesize %lu not 4096!\n", + sysconf(_SC_PAGESIZE)); + fflush(stderr); + abort(); + } +#endif /* area pointer is an ALLOC_ITEM, just the head of the list */ ap->next = NULL; } @@ -70,7 +126,7 @@ findptr(ALLOC_ITEM **lpp, char *ptr, Area *ap) internal_errorf("rogue pointer %zX", (size_t)ptr); #endif } - return (ap); + return ((void *)ap); } void * @@ -103,7 +159,7 @@ aresize(void *ptr, size_t numb, Area *ap) internal_errorf(Toomem, numb); /* this only works because Area is an ALLOC_ITEM */ lp->next = ap->next; - ap->next = lp; + ap->next = (void *)lp; /* return user item address */ return ((char *)lp + ALLOC_SIZE); } @@ -125,7 +181,7 @@ afree(void *ptr, Area *ap) void afreeall(Area *ap) { - ALLOC_ITEM *lp; + Area *lp; /* traverse group (linked list) */ while ((lp = ap->next) != NULL) { diff --git a/main.c b/main.c index e93a142..132d00a 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.307 2016/01/21 18:24:42 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.308 2016/02/24 01:44:46 tg Exp $"); extern char **environ; @@ -130,6 +130,9 @@ rndsetup(void) /* introduce variation (and yes, second arg MBZ for portability) */ mksh_TIME(bufptr->tv); +#ifdef MKSH_ALLOC_CATCH_UNDERRUNS + mprotect(((char *)bufptr) + 4096, 4096, PROT_READ | PROT_WRITE); +#endif h = chvt_rndsetup(bufptr, sizeof(*bufptr)); afree(cp, APERM); diff --git a/sh.h b/sh.h index b38e1e6..715bb21 100644 --- a/sh.h +++ b/sh.h @@ -175,9 +175,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.760 2016/01/21 19:58:13 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.761 2016/02/24 01:44:46 tg Exp $"); #endif -#define MKSH_VERSION "R52 2016/01/21" +#define MKSH_VERSION "R52 2016/02/23" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -699,16 +699,29 @@ im_sorry_dave(void) /* 1. internal structure */ +struct lalloc_area { + struct lalloc_area *next; +}; + struct lalloc { - struct lalloc *next; + struct lalloc_area *next; +#ifdef MKSH_ALLOC_CATCH_UNDERRUNS + size_t len; + char dummy[8192 - sizeof(struct lalloc_area *) - sizeof(size_t)]; +#endif }; /* 2. sizes */ #define ALLOC_ITEM struct lalloc #define ALLOC_SIZE (sizeof(ALLOC_ITEM)) +#ifndef MKSH_ALLOC_CATCH_UNDERRUNS +#define ALLOC_OVERHEAD ALLOC_SIZE +#else +#define ALLOC_OVERHEAD 0 +#endif -/* 3. group structure (only the same for lalloc.c) */ -typedef struct lalloc Area; +/* 3. group structure */ +typedef struct lalloc_area Area; EXTERN Area aperm; /* permanent object space */ @@ -1073,7 +1086,7 @@ EXTERN bool builtin_spec; EXTERN char *current_wd; /* input line size */ -#define LINE (4096 - ALLOC_SIZE) +#define LINE (4096 - ALLOC_OVERHEAD) /* * Minimum required space to work with on a line - if the prompt leaves * less space than this on a line, the prompt is truncated. From e9fc15847232732da87ef32cee7893d0b2c0b244 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 24 Feb 2016 01:45:59 +0000 Subject: [PATCH 5/7] =?UTF-8?q?plug=20a=20buffer=20underflow=20read=20we?= =?UTF-8?q?=20executed=20with=20*every*=20testsuite=20run=20and=20*every*?= =?UTF-8?q?=20interactive=20shell=20session=20(history=20didn=E2=80=99t=20?= =?UTF-8?q?contain=20anything=20when=20we=20tested=20for=20ignoredups)?= =?UTF-8?q?=E2=80=A6=20first=20caught=20by=20the=20new=20code=E2=80=A6=20d?= =?UTF-8?q?=E2=80=99uuuuuuuuuuh!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- histrap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/histrap.c b/histrap.c index 4c16fb8..5932ea3 100644 --- a/histrap.c +++ b/histrap.c @@ -27,7 +27,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.153 2016/01/21 18:24:40 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.154 2016/02/24 01:45:59 tg Exp $"); Trap sigtraps[ksh_NSIG + 1]; static struct sigaction Sigact_ign; @@ -658,7 +658,9 @@ histsave(int *lnp, const char *cmd, int svmode, bool ignoredups) strndupx(c, cmd, ccp - cmd, APERM); if (svmode != HIST_APPEND) { - if (ignoredups && !strcmp(c, *histptr) + if (ignoredups && + histptr >= history && + !strcmp(c, *histptr) #if !defined(MKSH_SMALL) && HAVE_PERSISTENT_HISTORY && !histsync() #endif From 08e1c6a9ea9a4fa1047aa28ba5e7c971b8af66c9 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 24 Feb 2016 01:47:32 +0000 Subject: [PATCH 6/7] =?UTF-8?q?ADELIM=20can=20be=20=E2=80=98}=E2=80=99=20t?= =?UTF-8?q?oo,=20not=20just=20=E2=80=98/=E2=80=99,=20in=20code=20that=20ch?= =?UTF-8?q?ecks=20for=20/=20vs.=20//=20caught=20by=20new=20code=20after=20?= =?UTF-8?q?segfault=20report=20by=20bef0rd=20on=20IRC=20(thanks!)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 10 +++++----- eval.c | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/check.t b/check.t index 4a4a228..c3c7c58 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.723 2016/02/11 20:19:44 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.724 2016/02/24 01:47:30 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,7 +30,7 @@ # (2013/12/02 20:39:44) http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R52 2016/01/21 + @(#)MIRBSD KSH R52 2016/02/23 description: Check version of shell. stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R52 2016/01/21 + @(#)LEGACY KSH R52 2016/02/23 description: Check version of legacy shell. stdin: @@ -1858,7 +1858,7 @@ stdin: [[ -n $BASH_VERSION ]] && shopt -s extglob x=1222321_ab/cde_b/c_1221 y=xyz - echo 1: ${x/2} + echo 1: ${x/2} . ${x/} echo 2: ${x//2} echo 3: ${x/+(2)} echo 4: ${x//+(2)} @@ -1890,7 +1890,7 @@ stdin: echo 30: ${x//\\a/9} echo 31: ${x/2/$y} expected-stdout: - 1: 122321_ab/cde_b/c_1221 + 1: 122321_ab/cde_b/c_1221 . 1222321_ab/cde_b/c_1221 2: 131_ab/cde_b/c_11 3: 1321_ab/cde_b/c_1221 4: 131_ab/cde_b/c_11 diff --git a/eval.c b/eval.c index fc31abb..540f969 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.181 2016/01/21 18:24:38 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.182 2016/02/24 01:47:32 tg Exp $"); /* * string expansion @@ -1151,7 +1151,7 @@ varsub(Expand *xp, const char *sp, const char *word, if (!stype && c == '/') { slen += 2; stype = c; - if (word[slen] == ADELIM) { + if (word[slen] == ADELIM && word[slen + 1] == c) { slen += 2; stype |= 0x80; } From 2a3773b70b6a416189abcb80558865acc1d634f1 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 24 Feb 2016 02:08:39 +0000 Subject: [PATCH 7/7] share structures better, less (void *) casts when we can stay typed --- lalloc.c | 26 +++++++++++++------------- sh.h | 16 ++++++++-------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/lalloc.c b/lalloc.c index 98aabde..a120760 100644 --- a/lalloc.c +++ b/lalloc.c @@ -23,7 +23,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.24 2016/02/24 01:44:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.25 2016/02/24 02:08:39 tg Exp $"); /* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */ #if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0) @@ -33,7 +33,7 @@ __RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.24 2016/02/24 01:44:46 tg Exp $"); #endif -static ALLOC_ITEM *findptr(ALLOC_ITEM **, char *, Area *); +static struct lalloc_common *findptr(struct lalloc_common **, char *, Area *); #ifndef MKSH_ALLOC_CATCH_UNDERRUNS #define ALLOC_ISUNALIGNED(p) (((size_t)(p)) % ALLOC_SIZE) @@ -45,7 +45,7 @@ static ALLOC_ITEM *findptr(ALLOC_ITEM **, char *, Area *); static void free_osimalloc(void *ptr) { - struct lalloc *lp = ptr; + struct lalloc_item *lp = ptr; if (munmap(lp, lp->len)) err(1, "free_osimalloc"); @@ -54,7 +54,7 @@ free_osimalloc(void *ptr) static void * remalloc(void *ptr, size_t size) { - struct lalloc *lp, *lold = ptr; + struct lalloc_item *lp, *lold = ptr; size = (size + 4095) & ~(size_t)4095; @@ -92,12 +92,12 @@ ainit(Area *ap) abort(); } #endif - /* area pointer is an ALLOC_ITEM, just the head of the list */ + /* area pointer and items share struct lalloc_common */ ap->next = NULL; } -static ALLOC_ITEM * -findptr(ALLOC_ITEM **lpp, char *ptr, Area *ap) +static struct lalloc_common * +findptr(struct lalloc_common **lpp, char *ptr, Area *ap) { void *lp; @@ -140,11 +140,11 @@ aresize2(void *ptr, size_t fac1, size_t fac2, Area *ap) void * aresize(void *ptr, size_t numb, Area *ap) { - ALLOC_ITEM *lp = NULL; + struct lalloc_common *lp = NULL; /* resizing (true) or newly allocating? */ if (ptr != NULL) { - ALLOC_ITEM *pp; + struct lalloc_common *pp; pp = findptr(&lp, ptr, ap); pp->next = lp->next; @@ -157,9 +157,9 @@ aresize(void *ptr, size_t numb, Area *ap) #endif ) internal_errorf(Toomem, numb); - /* this only works because Area is an ALLOC_ITEM */ + /* this only works because Area and ALLOC_ITEM share lalloc_common */ lp->next = ap->next; - ap->next = (void *)lp; + ap->next = lp; /* return user item address */ return ((char *)lp + ALLOC_SIZE); } @@ -168,7 +168,7 @@ void afree(void *ptr, Area *ap) { if (ptr != NULL) { - ALLOC_ITEM *lp, *pp; + struct lalloc_common *lp, *pp; pp = findptr(&lp, ptr, ap); /* unhook */ @@ -181,7 +181,7 @@ afree(void *ptr, Area *ap) void afreeall(Area *ap) { - Area *lp; + struct lalloc_common *lp; /* traverse group (linked list) */ while ((lp = ap->next) != NULL) { diff --git a/sh.h b/sh.h index 715bb21..f3c0bc4 100644 --- a/sh.h +++ b/sh.h @@ -175,7 +175,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.761 2016/02/24 01:44:46 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.762 2016/02/24 02:08:39 tg Exp $"); #endif #define MKSH_VERSION "R52 2016/02/23" @@ -699,20 +699,20 @@ im_sorry_dave(void) /* 1. internal structure */ -struct lalloc_area { - struct lalloc_area *next; +struct lalloc_common { + struct lalloc_common *next; }; -struct lalloc { - struct lalloc_area *next; +struct lalloc_item { + struct lalloc_common *next; #ifdef MKSH_ALLOC_CATCH_UNDERRUNS size_t len; - char dummy[8192 - sizeof(struct lalloc_area *) - sizeof(size_t)]; + char dummy[8192 - sizeof(struct lalloc_common *) - sizeof(size_t)]; #endif }; /* 2. sizes */ -#define ALLOC_ITEM struct lalloc +#define ALLOC_ITEM struct lalloc_item #define ALLOC_SIZE (sizeof(ALLOC_ITEM)) #ifndef MKSH_ALLOC_CATCH_UNDERRUNS #define ALLOC_OVERHEAD ALLOC_SIZE @@ -721,7 +721,7 @@ struct lalloc { #endif /* 3. group structure */ -typedef struct lalloc_area Area; +typedef struct lalloc_common Area; EXTERN Area aperm; /* permanent object space */