From cdc5e8a2c8284a569369443cacee7e1ebb887832 Mon Sep 17 00:00:00 2001 From: christos Date: Sat, 19 Nov 2005 18:01:42 +0000 Subject: Simplify error checking. --- caesar/caesar.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'caesar') diff --git a/caesar/caesar.c b/caesar/caesar.c index 63b8a553..831c5538 100644 --- a/caesar/caesar.c +++ b/caesar/caesar.c @@ -1,4 +1,4 @@ -/* $NetBSD: caesar.c,v 1.20 2005/11/19 14:22:21 rillig Exp $ */ +/* $NetBSD: caesar.c,v 1.21 2005/11/19 18:01:42 christos Exp $ */ /* * Copyright (c) 1989, 1993 @@ -48,7 +48,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ #if 0 static char sccsid[] = "@(#)caesar.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: caesar.c,v 1.20 2005/11/19 14:22:21 rillig Exp $"); +__RCSID("$NetBSD: caesar.c,v 1.21 2005/11/19 18:01:42 christos Exp $"); #endif #endif /* not lint */ @@ -129,11 +129,13 @@ get_rotation(const char *arg) errno = 0; rot = strtol(arg, &endp, 10); - if (!(errno == 0 && *endp == '\0' && 0 <= rot && rot <= INT_MAX)) { - errx(EXIT_FAILURE, "bad rotation value: %s", arg); - /* NOTREACHED */ - } - return (int) rot; + if (errno == 0 && (arg[0] == '\0' || *endp != '\0')) + errno = EINVAL; + if (errno == 0 && (rot < 0 || rot > INT_MAX)) + errno = ERANGE; + if (errno) + err(EXIT_FAILURE, "Bad rotation value `%s'", arg); + return (int)rot; } static void -- cgit v1.2.3-56-ge451