tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: pdksh
Le 17/05/15 16:50, Terry Moore a écrit :
>> -----Original Message-----
>> From: tech-userlevel-owner%NetBSD.org@localhost [mailto:tech-userlevel-
>> owner%NetBSD.org@localhost] On Behalf Of Richard PALO
>> Sent: Sunday, May 17, 2015 7:27
>> To: tech-userlevel%netbsd.org@localhost
>> Subject: pdksh
>>
>>> @@ -122,7 +126,7 @@ tenter(tp, n, h)
>>> }
>>>
>>> if (tp->nfree <= 0) { /* too full */
>>> - texpand(tp, 2*tp->size);
>>> + texpand(tp, min(INTMAX_MAX, 2*tp->size));
>>> goto Search;
>>> }
>
> Given that tp->size is an INT, 2*tp->size will be calculated as an int, not as intmax_t. So I don't think comparing to INTMAX_MAX does any good.
>
> In any case, comparing after multiplying is usually a bad idea. You need instead something like:
>
> 2 * min(INT_MAX/2, tp->size)
>
> (This assumes that 2 * (INT_MAX/2) will be <= INT_MAX, which is true for 2's complement arithmetic.)
>
> Best regards,
> --Terry
>
>
Yeah, not sure why it came out that way... I do prefer your equivalence function for a number of reasons...
Attached is the updated diff.
--
Richard PALO
diff --git a/bin/ksh/exec.c b/bin/ksh/exec.c
index 93c1aa2..4c7ef7e 100644
--- a/bin/ksh/exec.c
+++ b/bin/ksh/exec.c
@@ -83,6 +83,7 @@ execute(t, flags)
{
int i;
volatile int rv = 0;
+ volatile int rv_prop = 0; /* rv being propogated or newly generated? */
int pv[2];
char ** volatile ap;
char *s, *cp;
@@ -164,6 +165,7 @@ execute(t, flags)
case TPAREN:
rv = execute(t->left, flags|XFORK);
+ rv_prop = 1;
break;
case TPIPE:
@@ -284,6 +286,7 @@ execute(t, flags)
rv = execute(t->right, flags & XERROK);
else
flags |= XERROK;
+ rv_prop = 1;
break;
case TBANG:
@@ -332,6 +335,7 @@ execute(t, flags)
}
}
rv = 0; /* in case of a continue */
+ rv_prop = 1;
if (t->type == TFOR) {
while (*ap != NULL) {
setstr(global(t->str), *ap++, KSH_UNWIND_ERROR);
@@ -343,6 +347,7 @@ execute(t, flags)
for (;;) {
if (!(cp = do_selectargs(ap, is_first))) {
rv = 1;
+ rv_prop = 0;
break;
}
is_first = FALSE;
@@ -374,6 +379,7 @@ execute(t, flags)
rv = 0; /* in case of a continue */
while ((execute(t->left, XERROK) == 0) == (t->type == TWHILE))
rv = execute(t->right, flags & XERROK);
+ rv_prop = 1;
break;
case TIF:
@@ -383,6 +389,7 @@ execute(t, flags)
rv = execute(t->left, XERROK) == 0 ?
execute(t->right->left, flags & XERROK) :
execute(t->right->right, flags & XERROK);
+ rv_prop = 1;
break;
case TCASE:
@@ -395,10 +402,12 @@ execute(t, flags)
break;
Found:
rv = execute(t->left, flags & XERROK);
+ rv_prop = 1;
break;
case TBRACE:
rv = execute(t->left, flags & XERROK);
+ rv_prop = 1;
break;
case TFUNCT:
@@ -410,6 +419,7 @@ execute(t, flags)
* (allows "ls -l | time grep foo").
*/
rv = timex(t, flags & ~XEXEC);
+ rv_prop = 1;
break;
case TEXEC: /* an eval'd TCOM */
@@ -437,7 +447,7 @@ execute(t, flags)
quitenv(); /* restores IO */
if ((flags&XEXEC))
unwind(LEXIT); /* exit child */
- if (rv != 0 && !(flags & XERROK)) {
+ if ((rv != 0) && (rv_prop == 0) && !(flags & XERROK)) {
if (Flag(FERREXIT))
unwind(LERROR);
trapsig(SIGERR_);
diff --git a/bin/ksh/table.c b/bin/ksh/table.c
index 025b56d..4ceeea8 100644
--- a/bin/ksh/table.c
+++ b/bin/ksh/table.c
@@ -14,6 +14,10 @@ __RCSID("$NetBSD: table.c,v 1.4 2003/06/23 11:39:04 agc Exp $");
#define INIT_TBLS 8 /* initial table size (power of 2) */
+#ifndef min
+#define min(a, b) ((a) > (b) ? (b) : (a))
+#endif
+
static void texpand ARGS((struct table *tp, int nsize));
static int tnamecmp ARGS((void *p1, void *p2));
@@ -122,7 +126,7 @@ tenter(tp, n, h)
}
if (tp->nfree <= 0) { /* too full */
- texpand(tp, 2*tp->size);
+ texpand(tp, 2 * min(INT_MAX/2, tp->size));
goto Search;
}
diff --git a/bin/ksh/table.h b/bin/ksh/table.h
index 9dc42c8..dcab6d6 100644
--- a/bin/ksh/table.h
+++ b/bin/ksh/table.h
@@ -6,7 +6,7 @@
struct table {
Area *areap; /* area to allocate entries */
- short size, nfree; /* hash size (always 2^^n), free entries */
+ int size, nfree; /* hash size (always 2^^n), free entries */
struct tbl **tbls; /* hashed table items */
};
Home |
Main Index |
Thread Index |
Old Index