[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #60639] src/utils/addftinfo/addftinfo.cpp:119: double increment ?
From: |
G. Branden Robinson |
Subject: |
[bug #60639] src/utils/addftinfo/addftinfo.cpp:119: double increment ? |
Date: |
Thu, 20 May 2021 03:33:45 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 |
Update of bug #60639 (project groff):
Category: None => Utilities
Status: None => Need Info
_______________________________________________________
Follow-up Comment #1:
Thanks for the report, David!
Assigning to the new "Utilities" category I just created.
I haven't analyzed the correctness of this code yet, but here's some more
context. This is a hand-rolled option parser.
107 for (i = 1; i < argc && argv[i][0] == '-'; i++) {
108 if (argv[i][1] == '-' && argv[i][2] == '\0') {
109 i++;
110 break;
111 }
112 if (i + 1 >= argc)
113 usage("option requires argument");
114 size_t j;
115 for (j = 0;; j++) {
116 if (j >= sizeof(param_table)/sizeof(param_table[0]))
117 fatal("parameter '%1' not recognized", argv[i] + 1);
118 if (strcmp(param_table[j].name, argv[i] + 1) == 0)
119 break;
120 }
121 if (sscanf(argv[i+1], "%d", &(param.*(param_table[j].par))) != 1)
122 fatal("invalid option argument '%1'", argv[i+1]);
123 i++;
124 }
125 if (argc - i != 3)
126 usage("insufficient arguments");
This code is very old. Almost none of it has changed since the dawn of our
repository's history on 2 June 1991.
The for loops were revised (by original author James Clark) in 1995--not to
add redundant incrementations, but rather to dumb the code down to ISO C90
from what was then a GCC extension.
@@ -89,14 +89,16 @@ int main(int argc, char **argv)
param.comma_depth = DEFAULT_COMMA_DEPTH;
param.desc_depth = DEFAULT_DESC_DEPTH;
param.body_depth = DEFAULT_BODY_DEPTH;
- for (int i = 1; i < argc && argv[i][0] == '-'; i++) {
+ int i;
+ for (i = 1; i < argc && argv[i][0] == '-'; i++) {
if (argv[i][1] == '-' && argv[i][2] == '\0') {
i++;
break;
}
if (i + 1 >= argc)
usage();
- for (int j = 0;; j++) {
+ int j;
+ for (j = 0;; j++) {
if (j >= sizeof(param_table)/sizeof(param_table[0]))
fatal("parameter `%1' not recognized", argv[i] + 1);
if (strcmp(param_table[j].name, argv[i] + 1) == 0)
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?60639>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/