Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/factor Remove is_hex_str() (trying to guess if a numbe...



details:   https://anonhg.NetBSD.org/src/rev/792b4a2ae017
branches:  trunk
changeset: 977012:792b4a2ae017
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Oct 11 18:46:21 2020 +0000

description:
Remove is_hex_str() (trying to guess if a number was hex or not). It is not
documented and can lead to unexpected behavior.

diffstat:

 games/factor/factor.c |  30 +++---------------------------
 1 files changed, 3 insertions(+), 27 deletions(-)

diffs (65 lines):

diff -r 3211568dfeed -r 792b4a2ae017 games/factor/factor.c
--- a/games/factor/factor.c     Sun Oct 11 18:43:50 2020 +0000
+++ b/games/factor/factor.c     Sun Oct 11 18:46:21 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: factor.c,v 1.36 2020/10/11 17:18:34 christos Exp $     */
+/*     $NetBSD: factor.c,v 1.37 2020/10/11 18:46:21 christos Exp $     */
 /*
  * Copyright (c) 1989, 1993
  *     The Regents of the University of California.  All rights reserved.
@@ -41,7 +41,7 @@
 __SCCSID("@(#)factor.c 8.4 (Berkeley) 5/4/95");
 #endif
 #ifdef __RCSID
-__RCSID("$NetBSD: factor.c,v 1.36 2020/10/11 17:18:34 christos Exp $");
+__RCSID("$NetBSD: factor.c,v 1.37 2020/10/11 18:46:21 christos Exp $");
 #endif
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 356666 2020-01-12 20:25:11Z gad $");
@@ -120,7 +120,6 @@
 
 static void    BN_print_dec_fp(FILE *, const BIGNUM *);
 static void    convert_str2bn(BIGNUM **, char *);
-static bool    is_hex_str(char *);
 static void    pr_fact(BIGNUM *, int, int);    /* print factors of a value */
 static void    pr_print(BIGNUM *, int, int);   /* print a prime */
 static void    usage(void) __dead;
@@ -451,29 +450,6 @@
 
 #endif
 
-/*
- * Scan the string from left-to-right to see if the longest substring
- * is a valid hexadecimal number.
- */
-static bool
-is_hex_str(char *str)
-{
-       char c, *p;
-       bool saw_hex = false;
-
-       for (p = str; *p; p++) {
-               if (isdigit((unsigned char)*p))
-                       continue;
-               c = tolower((unsigned char)*p);
-               if (c >= 'a' && c <= 'f') {
-                       saw_hex = true;
-                       continue;
-               }
-               break;  /* Not a hexadecimal digit. */
-       }
-       return saw_hex;
-}
-
 /* Convert string pointed to by *str to a bignum.  */
 static void
 convert_str2bn(BIGNUM **val, char *p)
@@ -486,7 +462,7 @@
        if (*p == '0' && (p[1] == 'x' || p[1] == 'X')) {
                n = BN_hex2bn(val, p + 2);
        } else {
-               n = is_hex_str(p) ? BN_hex2bn(val, p) : BN_dec2bn(val, p);
+               n = BN_dec2bn(val, p);
        }
        if (n == 0)
                errx(1, "%s: illegal numeric format.", p);



Home | Main Index | Thread Index | Old Index