Kernel - Fixes from clang's scan-build tool
[tpg/acess2.git] / Kernel / system.c
index 7c5ff32..66f645f 100644 (file)
@@ -23,7 +23,7 @@ typedef struct
 }      tConfigFile;
 typedef struct
 {
-       char    *Name;          // Name
+       const char      *Name;          // Name
         int    MinArgs;        // Minimum number of arguments
         int    MaxArgs;        // Maximum number of arguments
        Uint    IntArgs;        // Bitmap of arguments that should be treated as integers
@@ -32,10 +32,10 @@ typedef struct
 }      tConfigCommand;
 
 // === IMPORTS ===
-extern void    Arch_LoadBootModules();
-extern int     Modules_LoadBuiltins();
+extern void    Arch_LoadBootModules(void);
+extern int     Modules_LoadBuiltins(void);
 extern void    Modules_SetBuiltinParams(char *Name, char *ArgString);
-extern void    Debug_SetKTerminal(char *File);
+extern void    Debug_SetKTerminal(const char *File);
 
 // === PROTOTYPES ===
 void   System_Init(char *Commandline);
@@ -64,7 +64,7 @@ const tConfigCommand  caConfigCommands[] = {
 #define NUM_CONFIG_COMMANDS    (sizeof(caConfigCommands)/sizeof(caConfigCommands[0]))
 
 // === GLOBALS ===
-char   *gsConfigScript = "/Acess/Conf/BootConf.cfg";
+const char     *gsConfigScript = "/Acess/Conf/BootConf.cfg";
 char   *argv[32];
  int   argc;
 
@@ -82,7 +82,7 @@ void System_Init(char *CommandLine)
        System_ExecuteCommandLine();
        
        // - Execute the Config Script
-       Log_Log("Config", "Executing config script...");
+       Log_Log("Config", "Executing config script '%s'", gsConfigScript);
        System_ExecuteScript();
        
        // Set the debug to be echoed to the terminal
@@ -99,7 +99,8 @@ void System_ParseCommandLine(char *ArgString)
         int    i;
        char    *str;
        
-       Log_Log("Config", "Kernel Invocation \"%s\"", ArgString);
+       Log_Log("Config", "Kernel Invocation (%p) \"%s\"", ArgString, ArgString);
+       Log_Log("Config", "Kernel Invocation '0x%x 0x%x'", ArgString[0], ArgString[1]);
        
        // --- Get Arguments ---
        str = ArgString;
@@ -126,7 +127,7 @@ void System_ParseCommandLine(char *ArgString)
                argc ++;        // Count last argument
        
        // --- Parse Arguments (Pass 1) ---
-       for( i = 1; i < argc; i++ )
+       for( i = 0; i < argc; i++ )
        {
                switch(argv[i][0])
                {
@@ -152,8 +153,9 @@ void System_ParseCommandLine(char *ArgString)
 void System_ExecuteCommandLine(void)
 {
         int    i;
-       for( i = 1; i < argc; i++ )
+       for( i = 0; i < argc; i++ )
        {
+               Log("argv[%i] = '%s'", i, argv[i]);
                switch(argv[i][0])
                {
                // --- VFS ---
@@ -219,7 +221,8 @@ void System_ParseVFS(char *Arg)
 }
 
 /**
- * \biref Parse a module argument string
+ * \brief Parse a module argument string
+ * \param Arg  Argument string
  */
 void System_ParseModuleArgs(char *Arg)
 {
@@ -315,6 +318,7 @@ void System_ExecuteScript(void)
        // Get length
        VFS_Seek(fp, 0, SEEK_END);
        fLen = VFS_Tell(fp);
+       Log_Debug("System", "VFS_Tell(%i) = %i", fp, fLen);
        VFS_Seek(fp, 0, SEEK_SET);
        // Read into memory buffer
        fData = malloc(fLen+1);
@@ -335,7 +339,8 @@ void System_ExecuteScript(void)
                if(line->Parts[0][0] == ':')    continue;       // Ignore labels
                
                // Prescan and eliminate variables
-               for( j = 1; j < line->nParts; j++ ) {
+               for( j = 1; j < line->nParts; j++ )
+               {
                        Log_Debug("Config", "Arg #%i is '%s'", j, line->Parts[j]);
                        bReplaced[j] = 0;
                        if( line->Parts[j][0] != '$' )  continue;
@@ -353,13 +358,16 @@ void System_ExecuteScript(void)
                        bReplaced[j] = 1;
                }
                
+               // Find the command name
                for( j = 0; j < NUM_CONFIG_COMMANDS; j++ )
                {
                        Uint    args[N_MAX_ARGS];
+                       
                        if(strcmp(line->Parts[0], caConfigCommands[j].Name) != 0)       continue;
                        
                        Log_Debug("Config", "Command '%s', %i args passed", line->Parts[0], line->nParts-1);
                        
+                       // Check against minimum argument count
                        if( line->nParts - 1 < caConfigCommands[j].MinArgs ) {
                                Log_Warning("Config",
                                        "Configuration command '%s' requires at least %i arguments, %i given",
@@ -368,6 +376,7 @@ void System_ExecuteScript(void)
                                break;
                        }
                        
+                       // Check for extra arguments
                        if( line->nParts - 1 > caConfigCommands[j].MaxArgs ) {
                                Log_Warning("Config",
                                        "Configuration command '%s' takes at most %i arguments, %i given",
@@ -376,13 +385,15 @@ void System_ExecuteScript(void)
                                break;
                        }
                        
+                       // Fill in defaults
                        for( k = caConfigCommands[j].MaxArgs-1; k > line->nParts - 1; k-- ) {
                                args[k] = caConfigCommands[j].OptDefaults[k];
                        }
                        
+                       // Convert arguments to integers
                        for( k = line->nParts-1; k--; )
                        {
-                               if( caConfigCommands[j].IntArgs & (1 << k) ) {
+                               if( k < 32 && (caConfigCommands[j].IntArgs & (1 << k)) ) {
                                        args[k] = atoi(line->Parts[k+1]);
                                }
                                else {
@@ -545,6 +556,7 @@ tConfigFile *System_Int_ParseFile(char *FileData)
                start = ptr;
                
                ret->Lines[i].nParts = 0;
+               ret->Lines[i].Parts = NULL;
                
                // Count parts
                for(;;)
@@ -637,6 +649,12 @@ tConfigFile        *System_Int_ParseFile(char *FileData)
                }
        }
        
+       if( i < ret->nLines ) {
+               ret->Lines[i].nParts = 0;
+               ret->Lines[i].Parts = NULL;
+               Log_Log("System", "Cleaning up final empty line");
+       }
+       
        LEAVE('p', ret);
        return ret;
 }

UCC git Repository :: git.ucc.asn.au