Source-Changes-HG archive

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

[src/trunk]: src/usr.sbin/config PR/23490: Jason Thorpe: 64-bit config(8) bre...



details:   https://anonhg.NetBSD.org/src/rev/1b0fd97b9f19
branches:  trunk
changeset: 555507:1b0fd97b9f19
user:      christos <christos%NetBSD.org@localhost>
date:      Wed Nov 19 18:06:13 2003 +0000

description:
PR/23490: Jason Thorpe: 64-bit config(8) breaks negative RTC_OFFSET
Fixed by preserving the format of the input number and using it to format
the output number. This avoids the -10 < n < 10 kludge.

diffstat:

 usr.sbin/config/defs.h |   7 ++++++-
 usr.sbin/config/gram.y |  39 +++++++++++++++++++++------------------
 usr.sbin/config/scan.l |  11 +++++++----
 3 files changed, 34 insertions(+), 23 deletions(-)

diffs (201 lines):

diff -r b6bb2bb5850c -r 1b0fd97b9f19 usr.sbin/config/defs.h
--- a/usr.sbin/config/defs.h    Wed Nov 19 16:50:09 2003 +0000
+++ b/usr.sbin/config/defs.h    Wed Nov 19 18:06:13 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.14 2003/10/27 00:12:44 lukem Exp $  */
+/*     $NetBSD: defs.h,v 1.15 2003/11/19 18:06:13 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -404,6 +404,11 @@
        int     used;
 } locators;
 
+struct numconst {
+       int64_t val;
+       int fmt;
+};
+
 /* files.c */
 void   initfiles(void);
 void   checkfiles(void);
diff -r b6bb2bb5850c -r 1b0fd97b9f19 usr.sbin/config/gram.y
--- a/usr.sbin/config/gram.y    Wed Nov 19 16:50:09 2003 +0000
+++ b/usr.sbin/config/gram.y    Wed Nov 19 18:06:13 2003 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.45 2003/11/18 18:47:36 fvdl Exp $   */
+/*     $NetBSD: gram.y,v 1.46 2003/11/19 18:06:13 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -51,7 +51,8 @@
 #include "defs.h"
 #include "sem.h"
 
-#define        FORMAT(n) ((n) > -10 && (n) < 10 ? "%lld" : "0x%llx")
+#define        FORMAT(n) (((n).fmt == 8 && (n).val != 0) ? "0%llo" : \
+    ((n).fmt == 16) ? "0x%llx" : "%lld")
 
 #define        stop(s) error(s), exit(1)
 
@@ -94,6 +95,7 @@
        struct  deva *deva;
        struct  nvlist *list;
        const char *str;
+       struct  numconst num;
        int64_t val;
 }
 
@@ -102,7 +104,7 @@
 %token FILE_SYSTEM FLAGS IDENT INCLUDE XMACHINE MAJOR MAKEOPTIONS
 %token MAXUSERS MAXPARTITIONS MINOR ON OPTIONS PACKAGE PREFIX PSEUDO_DEVICE
 %token ROOT SOURCE TYPE WITH NEEDS_COUNT NEEDS_FLAG NO BLOCK CHAR DEVICE_MAJOR
-%token <val> NUMBER
+%token <num> NUMBER
 %token <str> PATHNAME QSTRING WORD EMPTY
 %token ENDDEFS
 
@@ -127,7 +129,8 @@
 %type  <str>   device_instance
 %type  <str>   attachment
 %type  <str>   value
-%type  <val>   major_minor signed_number npseudo
+%type  <val>   major_minor npseudo
+%type  <num>   signed_number
 %type  <val>   flags_opt
 %type  <str>   deffs
 %type  <list>  deffses
@@ -197,11 +200,11 @@
                                        { adddevm($2, $3, $4, $5); };
 
 device_major_block:
-       BLOCK NUMBER                    { $$ = $2; } |
+       BLOCK NUMBER                    { $$ = $2.val; } |
        /* empty */                     { $$ = -1; };
 
 device_major_char:
-       CHAR NUMBER                     { $$ = $2; } |
+       CHAR NUMBER                     { $$ = $2.val; } |
        /* empty */                     { $$ = -1; };
 
 /* order of options is important, must use right recursion */
@@ -283,8 +286,8 @@
                                        { defdev($2, $3, $4, 0); } |
        ATTACH devbase AT atlist devattach_opt attrs_opt
                                        { defdevattach($5, $2, $4, $6); } |
-       MAXPARTITIONS NUMBER            { maxpartitions = $2; } |
-       MAXUSERS NUMBER NUMBER NUMBER   { setdefmaxusers($2, $3, $4); } |
+       MAXPARTITIONS NUMBER            { maxpartitions = $2.val; } |
+       MAXUSERS NUMBER NUMBER NUMBER   { setdefmaxusers($2.val, $3.val, $4.val); } |
        DEFPSEUDO devbase interface_opt attrs_opt
                                        { defdev($2, $3, $4, 1); } |
        MAJOR '{' majorlist '}';
@@ -347,11 +350,11 @@
        locname locdefault              { $$ = new_nsi($1, $2, 0); } |
        locname                         { $$ = new_nsi($1, NULL, 0); } |
        '[' locname locdefault ']'      { $$ = new_nsi($2, $3, 1); } |
-       locname '[' NUMBER ']'          { $$ = mk_nsis($1, $3, NULL, 0); } |
+       locname '[' NUMBER ']'          { $$ = mk_nsis($1, $3.val, NULL, 0); } |
        locname '[' NUMBER ']' locdefaults
-                                       { $$ = mk_nsis($1, $3, $5, 0); } |
+                                       { $$ = mk_nsis($1, $3.val, $5, 0); } |
        '[' locname '[' NUMBER ']' locdefaults ']'
-                                       { $$ = mk_nsis($2, $4, $6, 1); };
+                                       { $$ = mk_nsis($2, $4.val, $6, 1); };
 
 locname:
        WORD                            { $$ = $1; } |
@@ -381,7 +384,7 @@
        EMPTY                           { $$ = $1; } |
        signed_number                   { char bf[40];
                                          (void)snprintf(bf, sizeof(bf),
-                                             FORMAT($1), $1);
+                                             FORMAT($1), $1.val);
                                          $$ = intern(bf); };
 
 stringvalue:
@@ -394,7 +397,7 @@
 
 signed_number:
        NUMBER                          { $$ = $1; } |
-       '-' NUMBER                      { $$ = -$2; };
+       '-' NUMBER                      { $$.fmt = $2.fmt; $$.val = -$2.val; };
 
 attrs_opt:
        ':' attrs                       { $$ = $2; } |
@@ -412,7 +415,7 @@
        majordef;
 
 majordef:
-       devbase '=' NUMBER              { setmajor($1, $3); };
+       devbase '=' NUMBER              { setmajor($1, $3.val); };
 
 
 /*
@@ -435,7 +438,7 @@
        MAKEOPTIONS mkopt_list |
        NO OPTIONS no_opt_list |
        OPTIONS opt_list |
-       MAXUSERS NUMBER                 { setmaxusers($2); } |
+       MAXUSERS NUMBER                 { setmaxusers($2.val); } |
        IDENT stringvalue               { setident($2); } |
        CONFIG conf root_spec sysparam_list
                                        { addconf(&conf); } |
@@ -521,13 +524,13 @@
        major_minor                     { $$ = new_si(NULL, $1); };
 
 major_minor:
-       MAJOR NUMBER MINOR NUMBER       { $$ = makedev($2, $4); };
+       MAJOR NUMBER MINOR NUMBER       { $$ = makedev($2.val, $4.val); };
 
 on_opt:
        ON | /* empty */;
 
 npseudo:
-       NUMBER                          { $$ = $1; } |
+       NUMBER                          { $$ = $1.val; } |
        /* empty */                     { $$ = 1; };
 
 device_instance:
@@ -548,7 +551,7 @@
        WORD '?'                        { $$ = new_ns($1, NULL); };
 
 flags_opt:
-       FLAGS NUMBER                    { $$ = $2; } |
+       FLAGS NUMBER                    { $$ = $2.val; } |
        /* empty */                     { $$ = 0; };
 
 %%
diff -r b6bb2bb5850c -r 1b0fd97b9f19 usr.sbin/config/scan.l
--- a/usr.sbin/config/scan.l    Wed Nov 19 16:50:09 2003 +0000
+++ b/usr.sbin/config/scan.l    Wed Nov 19 18:06:13 2003 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: scan.l,v 1.41 2003/11/18 18:47:36 fvdl Exp $   */
+/*     $NetBSD: scan.l,v 1.42 2003/11/19 18:06:13 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993
@@ -148,15 +148,18 @@
                return QSTRING;
        }
 0[0-7]*        {
-               yylval.val = strtoll(yytext, NULL, 8);
+               yylval.num.fmt = 8;
+               yylval.num.val = strtoll(yytext, NULL, 8);
                return NUMBER;
        }
 0[xX][0-9a-fA-F]+ {
-               yylval.val = strtoull(yytext + 2, NULL, 16);
+               yylval.num.fmt = 16;
+               yylval.num.val = strtoull(yytext + 2, NULL, 16);
                return NUMBER;
        }
 [1-9][0-9]* {
-               yylval.val = strtoll(yytext, NULL, 10);
+               yylval.num.fmt = 10;
+               yylval.num.val = strtoll(yytext, NULL, 10);
                return NUMBER;
        }
 \n[ \t] {



Home | Main Index | Thread Index | Old Index