Kernel - Fixes from clang's scan-build tool
authorJohn Hodge <[email protected]>
Mon, 8 Aug 2011 13:17:14 +0000 (21:17 +0800)
committerJohn Hodge <[email protected]>
Mon, 8 Aug 2011 13:17:14 +0000 (21:17 +0800)
14 files changed:
Kernel/adt.c
Kernel/arch/x86_64/mm_phys.c
Kernel/arch/x86_64/proc.c
Kernel/bin/elf.c
Kernel/binary.c
Kernel/drv/iocache.c
Kernel/drv/proc.c
Kernel/heap.c
Kernel/system.c
Kernel/threads.c
Modules/IPStack/routing.c
Modules/IPStack/udp.c
Modules/Storage/FDD/fdd.c
Usermode/Applications/CLIShell_src/main.c

index 1a001c9..ef2ae05 100644 (file)
@@ -60,7 +60,7 @@ size_t RingBuffer_Write(tRingBuffer *Buffer, const void *Source, size_t Length)
        tmpLen = Buffer->Length;
        SHORTREL( &Buffer->Lock );
 
-       bufEnd = (Buffer->Start + Buffer->Length) % Buffer->Space;
+       bufEnd = (tmpStart + Buffer->Length) % Buffer->Space;
        endSpace = Buffer->Space - bufEnd;
        
        // Force to bounds
index 6955505..fcc8547 100644 (file)
@@ -249,8 +249,8 @@ void MM_InitPhys_Multiboot(tMBoot_Info *MBoot)
                if(base & 63) {
                        Uint64  val = -1LL << (base & 63);
                        gaSuperBitmap[base / 64] &= ~val;
-                       size -= (base & 63);
-                       base += 64 - (base & 63);
+//                     size -= (base & 63);
+//                     base += 64 - (base & 63);
                }
        }
        
@@ -403,9 +403,9 @@ tPAddr MM_AllocPhysRange(int Pages, int MaxBits)
        {
                // Oops. ok, let's do an expensive check (scan down the list
                // until a free range is found)
-               nFree = 1;
-               addr = giPhysRangeLast[ rangeID ];
-               // TODO
+//             nFree = 1;
+//             addr = giPhysRangeLast[ rangeID ];
+               // TODO: Expensive Check
                Mutex_Release(&glPhysicalPages);
                // TODO: Page out
                // ATM. Just Warning
index 8691100..06c7d85 100644 (file)
@@ -287,10 +287,10 @@ void ArchThreads_Init(void)
        #if USE_MP
        }
        for(pos=0;pos<giNumCPUs;pos++) {
-       #endif
                __asm__ __volatile__ ("ltr %%ax"::"a"(0x38+pos*16));
-       #if USE_MP
        }
+       #else
+       __asm__ __volatile__ ("ltr %%ax"::"a"(0x38));
        #endif
        
        // Set Debug registers
@@ -798,7 +798,7 @@ void Proc_Scheduler(int CPU)
                thread = gaCPUs[CPU].IdleThread;
                //Warning("Hmm... Threads_GetNextToRun returned NULL, I don't think this should happen.\n");
                //LogF("Zzzzz.\n");
-               return;
+               //return;
        }
        
        #if DEBUG_TRACE_SWITCH
index b55011b..d04dbda 100644 (file)
@@ -347,6 +347,10 @@ int Elf_Relocate(void *Base)
                }\r
        }\r
 \r
+       if( !dynsymtab && iSymCount > 0 ) {\r
+               Log_Warning("ELF", "Elf_Relocate: No Dynamic symbol table, but count >0");\r
+               return 0;\r
+       }\r
 \r
        // Alter Symbols to true base\r
        for(i = 0; i < iSymCount; i ++)\r
@@ -409,7 +413,7 @@ int Elf_Relocate(void *Base)
                for( i = 0; i < j; i++ )\r
                {\r
                        ptr = (void*)(iBaseDiff + rela[i].r_offset);\r
-                       if( !Elf_Int_DoRelocate(rel[i].r_info, ptr, rela[i].r_addend, dynsymtab, (Uint)Base) ) {\r
+                       if( !Elf_Int_DoRelocate(rela[i].r_info, ptr, rela[i].r_addend, dynsymtab, (Uint)Base) ) {\r
                                bFailed = 1;\r
                        }\r
                }\r
@@ -451,8 +455,8 @@ int Elf_Relocate(void *Base)
                return 0;\r
        }\r
        \r
-       LEAVE('x', hdr->entrypoint);\r
-       return hdr->entrypoint;\r
+       LEAVE('x', 1);\r
+       return 1;\r
 }\r
 \r
 /**\r
index 0f5183c..58d86d7 100644 (file)
@@ -744,7 +744,7 @@ void *Binary_LoadKernel(const char *File)
        // Relocate Library
        if( !Binary_Relocate( (void*)base ) )
        {
-               Warning("[BIN ] Relocation of '%s' failed, unloading", sTruePath);
+               Log_Warning("BIN", "Relocation of '%s' failed, unloading", sTruePath);
                Binary_Unload( (void*)base );
                Binary_Dereference( pBinary );
                LEAVE('n');
index ba822df..774c497 100644 (file)
@@ -190,6 +190,10 @@ int IOCache_Add( tIOCache *Cache, Uint64 Sector, void *Buffer )
                                oldestPrev = prev;
                        }
                }
+               if( !oldest ) {
+                       Log_Error("IOCache", "Cache full, but also empty");
+                       return -1;
+               }
                // Remove from list, write back and free
                oldestPrev->Next = oldest->Next;
                if(oldest->LastWrite && Cache->Mode != IOCACHE_VIRTUAL)
index 0d1ae52..8056114 100644 (file)
@@ -301,7 +301,10 @@ int SysFS_RemoveFile(int ID)
        }
        
        // Remove from parent directory
-       prev->Next = ent->Next;
+       if(prev)
+               prev->Next = ent->Next;
+       else
+               parent->Node.ImplPtr = ent->Next;
        
        // Free if not in use
        if(file->Node.ReferenceCount == 0)
index a9e9931..fc99f56 100644 (file)
@@ -571,7 +571,8 @@ void Heap_Dump(void)
        #if !VERBOSE_DUMP
        Log_Log("Heap", "%p (%P): 0x%08lx %i %4C",
                head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
-       Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
+       if(foot)
+               Log_Log("Heap", "Backlink = %p %4C", foot->Head, &foot->Magic);
        if(head->File) {
                Log_Log("Heap", "%sowned by %s:%i",
                        (head->Magic==MAGIC_FREE?"was ":""), head->File, head->Line);
@@ -680,10 +681,16 @@ void Heap_Stats(void)
 
        Log_Log("Heap", "%i blocks (0x%x bytes)", nBlocks, totalBytes);
        Log_Log("Heap", "%i free blocks (0x%x bytes)", nFree, freeBytes);
-       frag = (nFree-1)*10000/nBlocks;
+       if(nBlocks != 0)
+               frag = (nFree-1)*10000/nBlocks;
+       else
+               frag = 0;
        Log_Log("Heap", "%i.%02i%% Heap Fragmentation", frag/100, frag%100);
        avgAlloc = (totalBytes-freeBytes)/(nBlocks-nFree);
-       overhead = (sizeof(tHeapFoot)+sizeof(tHeapHead))*10000/avgAlloc;
+       if(avgAlloc != 0)
+               overhead = (sizeof(tHeapFoot)+sizeof(tHeapHead))*10000/avgAlloc;
+       else
+               overhead = 0;
        Log_Log("Heap", "Average allocation: %i bytes, Average Overhead: %i.%02i%%",
                avgAlloc, overhead/100, overhead%100
                );
index 1726fef..66f645f 100644 (file)
@@ -393,7 +393,7 @@ void System_ExecuteScript(void)
                        // 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 {
index 4ab76ff..fa6f6e0 100644 (file)
@@ -1291,7 +1291,7 @@ tThread *Threads_GetNextToRun(int CPU, tThread *Last)
                        }
                        // If we fall onto the same queue again, special handling is
                        // needed
-                       if( i == Last->Priority ) {
+                       if( Last && i == Last->Priority ) {
                                tThread *savedThread = thread;
                                
                                // Find the next unscheduled thread in the list
index c37e744..6379302 100644 (file)
@@ -348,10 +348,10 @@ tRoute *IPStack_FindRoute(int AddressType, tInterface *Interface, void *Address)
        {
                rt = &Interface->Route;
                // Make sure route is up to date
-               memcpy(rt->Network, iface->Address, addrSize);
+               memcpy(rt->Network, Interface->Address, addrSize);
                memset(rt->NextHop, 0, addrSize);
                rt->Metric = DEFAUTL_METRIC;
-               rt->SubnetBits = iface->SubnetBits;
+               rt->SubnetBits = Interface->SubnetBits;
                
                if( IPStack_CompareAddress(AddressType, rt->Network, Address, rt->SubnetBits) )
                {
index 6f3abc6..9e54701 100644 (file)
@@ -257,7 +257,7 @@ Uint64 UDP_Channel_Write(tVFS_Node *Node, Uint64 Offset, Uint64 Length, void *Bu
 
        data = (char*)Buffer + ofs;
 
-       UDP_SendPacketTo(chan, ep->AddrType, &ep->Addr, ep->Port, Buffer, (size_t)Length - ofs);
+       UDP_SendPacketTo(chan, ep->AddrType, &ep->Addr, ep->Port, data, (size_t)Length - ofs);
        
        return 0;
 }
index 801f2eb..42150a9 100644 (file)
@@ -176,7 +176,7 @@ int FDD_Install(char **Arguments)
 
        // Ensure the FDD version is 0x90
        {
-               Uint8   tmp;
+               Uint8   tmp = 0;
                FDD_int_SendByte(cPORTBASE[0], CMD_VERSION);
                FDD_int_GetByte(cPORTBASE[0], &tmp);
                if( tmp != 0x90 ) {
@@ -584,7 +584,7 @@ int FDD_WriteSector(Uint32 Disk, Uint64 LBA, void *Buffer)
  */
 int FDD_int_SeekTrack(int disk, int head, int track)
 {
-       Uint8   sr0, cyl;
+       Uint8   sr0=0, cyl=0;
         int    base;
        
        base = cPORTBASE[disk>>1];
index 807527b..4378d1d 100644 (file)
@@ -145,7 +145,7 @@ int main(int argc, char *argv[], char *envp[])
        }\r
 }\r
 \r
-#if USE_READLINE\r
+#if !USE_READLINE\r
 /**\r
  * \fn char *ReadCommandLine(int *Length)\r
  * \brief Read from the command line\r

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