File: do-not-use-loop-variable.patch

package info (click to toggle)
units 2.26-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,068 kB
  • sloc: ansic: 6,851; python: 969; sh: 903; yacc: 605; makefile: 491; perl: 435
file content (44 lines) | stat: -rw-r--r-- 1,703 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Description: Do not increment the loop variable
 When parsing FN_DOMAIN intervals, newfunction reuses 
 the loop variable i, causing the segmentation fault
 due to arrays out of bounds access.
 This patch introduces a separate variable for the
 interval parsing.
Author: Vladimir Petko <vladimir.petko@canonical.com>
Bug-Ubuntu: https://bugs.launchpad.net/bugs/2144689
Forwarded: no
Last-Update: 2026-03-18

--- a/units.c
+++ b/units.c
@@ -1377,7 +1377,7 @@
   char *params[MAX_FUNC_PARAMS];
   char *forward_dim[MAX_FUNC_PARAMS];
   int param_count, extrachars;
-  int looking_for_keywords,i;
+  int looking_for_keywords,i,param_index;
   struct interval domain[MAX_FUNC_PARAMS];
   struct interval range; 
   int noerror = 0;
@@ -1526,17 +1526,17 @@
         if (i==FN_DOMAIN){
           char *x=unitdef;
           unitdef = parseinterval(unitdef, domain, unitname, linenum, file, errfile, &errors, "domain=");
-          i=1;
+          param_index=1;
           while(*unitdef && strchr(",[(",*unitdef)){
 	    if (*unitdef==',') unitdef++;
-            if (i>=param_count){
+            if (param_index>=param_count){
               if (errfile) fprintf(errfile,
                      "%s: definition of function '%s' has too many intervals in domain in '%s' line %d\n",
                      progname,unitname,file,linenum);
               BADFILE;
             }
-            unitdef = parseinterval(unitdef, domain+i, unitname, linenum, file, errfile, &errors, "domain=");
-            i++;
+            unitdef = parseinterval(unitdef, domain+param_index, unitname, linenum, file, errfile, &errors, "domain=");
+            param_index++;
           }
         }
         if (*unitdef!=' '){