From 5161342b9bb16b9f9f6f8447f2f93def5bd630f7 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 9 Feb 2011 13:08:27 +0000 Subject: [PATCH] fix warning about signed vs. unsigned comparision and potential truncation error --- check.t | 4 ++-- histrap.c | 15 +++++++++++---- sh.h | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/check.t b/check.t index 8ad4a45..5d400d7 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.405 2011/02/03 15:57:49 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.406 2011/02/09 13:08:24 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 $ @@ -25,7 +25,7 @@ # http://www.research.att.com/~gsf/public/ifs.sh expected-stdout: - @(#)MIRBSD KSH R39 2011/02/03 + @(#)MIRBSD KSH R39 2011/02/09 description: Check version of shell. stdin: diff --git a/histrap.c b/histrap.c index 53c5898..61b290c 100644 --- a/histrap.c +++ b/histrap.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.104 2011/01/30 02:18:20 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.105 2011/02/09 13:08:25 tg Exp $"); /*- * MirOS: This is the default mapping type, and need not be specified. @@ -274,9 +274,16 @@ c_fc(const char **wp) if (stat(tf->name, &statb) < 0) n = 128; else { - if (notoktoadd(statb.st_size, 1 + X_EXTRA)) { - bi_errorf(T_intovfl, - (unsigned long)statb.st_size, '+', + unsigned long st_sizeUL; + + /* we pretty much assume ulong >= size_t */ + st_sizeUL = (unsigned long)statb.st_size; + if ( + /* too big, truncated by the cast */ + statb.st_size != (long)st_sizeUL || + /* a few additional bytes do not fit */ + notoktoadd(st_sizeUL, 1 + X_EXTRA)) { + bi_errorf(T_intovfl, st_sizeUL, '+', 1UL + X_EXTRA); goto errout; } diff --git a/sh.h b/sh.h index 85219cf..6fd7503 100644 --- a/sh.h +++ b/sh.h @@ -154,9 +154,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.427 2011/02/03 15:57:52 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.428 2011/02/09 13:08:27 tg Exp $"); #endif -#define MKSH_VERSION "R39 2011/02/03" +#define MKSH_VERSION "R39 2011/02/09" #ifndef MKSH_INCLUDES_ONLY