[MAN] AnalyzeArgv(): Fix 2 overruns related to element (#703)
authorSerge Gautherie <32623169+SergeGautherie@users.noreply.github.com>
Fri, 27 Jul 2018 19:53:50 +0000 (21:53 +0200)
committerHermès BÉLUSCA - MAÏTO <hermes.belusca-maito@reactos.org>
Fri, 27 Jul 2018 19:53:50 +0000 (21:53 +0200)
- Also use _countof().
- Also add braces.
- Also enforce consistent "no spaces" style.

Thanks to "devpao" for pointing to this function.

ROSAPPS-344

modules/rosapps/applications/sysutils/man/man.c

index edc12d2..3c54eb3 100644 (file)
@@ -88,7 +88,7 @@ Usage()
 int
 AnalyzeArgv(char *argument)
 {
-    int element=0;
+    int element;
     char HelpFlag=0;
     char *keys[]={"--help","/h","/?","-h"};
     char *sections[]={".1",".2",".3",".4",".5",".6",".7",".8",".9"};
@@ -96,25 +96,32 @@ AnalyzeArgv(char *argument)
 
     strcpy(filename,argument); //save argument value
 
-    for(element=0; element < 5;element++)
+    for(element=0;element<_countof(keys);element++)
+    {
      if(!strcmp(keys[element],argument))
      {
       Usage();
       HelpFlag=1;
      }
+    }
 
    element = 0;
 
    if(!HelpFlag)
+   {
 
    if(OpenF(filename))
-    while(OpenF(strcat(filename,sections[element])) && (element<9))
+   {
+    while(element<_countof(sections)&&OpenF(strcat(filename,sections[element])))
     {
      strcpy(filename,argument);
      element++;
     }
 
-    if(element>8) printf("No manual for %s\n",argument);
+    if(element>=_countof(sections)) printf("No manual for %s\n",argument);
+   }
+
+   }
 
     return element;
 }