rewrite some code; bug found by HP's C compiler

This commit is contained in:
tg 2007-06-21 16:04:46 +00:00
parent f738b28b3b
commit d42f966d22
3 changed files with 10 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.114 2007/06/17 00:50:07 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.115 2007/06/21 16:04:45 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R29 2007/06/17
@(#)MIRBSD KSH R29 2007/06/21
description:
Check version of shell.
category: pdksh

12
edit.c
View File

@ -5,7 +5,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.103 2007/06/15 22:00:00 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.104 2007/06/21 16:04:46 tg Exp $");
/* tty driver characters we are interested in */
typedef struct {
@ -722,11 +722,11 @@ glob_path(int flags, const char *pat, XPtrV *wp, const char *lpath)
static int
x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
{
size_t add, wlen;
size_t add = 0, wlen = len;
const char *ifs = str_val(local("IFS", 0));
int rval = 0;
for (add = 0, wlen = len; wlen - add > 0; add++) {
while (wlen - add > 0)
if (vstrchr("\\$()[{}*&;#|<>\"'`", s[add]) ||
vstrchr(ifs, s[add])) {
if (putbuf_func(s, add) != 0) {
@ -741,9 +741,9 @@ x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
add++;
wlen -= add;
s += add;
add = -1; /* after the increment it will go to 0 */
}
}
add = 0;
} else
++add;
if (wlen > 0 && rval == 0)
rval = putbuf_func(s, wlen);

4
sh.h
View File

@ -8,8 +8,8 @@
/* $OpenBSD: c_test.h,v 1.4 2004/12/20 11:34:26 otto Exp $ */
/* $OpenBSD: tty.h,v 1.5 2004/12/20 11:34:26 otto Exp $ */
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.148 2007/06/17 00:50:09 tg Exp $"
#define MKSH_VERSION "R29 2007/06/17"
#define MKSH_SH_H_ID "$MirOS: src/bin/mksh/sh.h,v 1.149 2007/06/21 16:04:46 tg Exp $"
#define MKSH_VERSION "R29 2007/06/21"
#if HAVE_SYS_PARAM_H
#include <sys/param.h>