Source-Changes-HG archive

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

[src/trunk]: src/games/factor - Accept octal input.



details:   https://anonhg.NetBSD.org/src/rev/6ff0ba413735
branches:  trunk
changeset: 940148:6ff0ba413735
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Oct 04 19:32:15 2020 +0000

description:
- Accept octal input.
- Don't play with the original string so we can print it.

diffstat:

 games/factor/factor.c |  11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diffs (32 lines):

diff -r cde94c9b11ee -r 6ff0ba413735 games/factor/factor.c
--- a/games/factor/factor.c     Sun Oct 04 19:21:13 2020 +0000
+++ b/games/factor/factor.c     Sun Oct 04 19:32:15 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: factor.c,v 1.30 2020/10/03 22:27:00 christos Exp $     */
+/*     $NetBSD: factor.c,v 1.31 2020/10/04 19:32:15 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.30 2020/10/03 22:27:00 christos Exp $");
+__RCSID("$NetBSD: factor.c,v 1.31 2020/10/04 19:32:15 christos Exp $");
 #endif
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/usr.bin/factor/factor.c 356666 2020-01-12 20:25:11Z gad $");
@@ -424,9 +424,10 @@
        if (*p == '-')
                errx(1, "negative numbers aren't permitted.");
        if (*p == '0') {
-               p++;
-               if (*p == 'x' || *p == 'X')
-                       n = BN_hex2bn(val, ++p);
+               if (p[1] == 'x' || p[1] == 'X')
+                       n = BN_hex2bn(val, p + 2);
+               else
+                       n = BN_oct2bn(val, p + 1);
        } else {
                n = is_hex_str(p) ? BN_hex2bn(val, p) : BN_dec2bn(val, p);
        }



Home | Main Index | Thread Index | Old Index