From: John Hodge Date: Mon, 8 Aug 2011 13:17:14 +0000 (+0800) Subject: Kernel - Fixes from clang's scan-build tool X-Git-Tag: rel0.11~156 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=952891ddb96a341c0e24ecb7dec6361c7bbeaece;p=tpg%2Facess2.git Kernel - Fixes from clang's scan-build tool --- diff --git a/Kernel/adt.c b/Kernel/adt.c index 1a001c99..ef2ae058 100644 --- a/Kernel/adt.c +++ b/Kernel/adt.c @@ -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 diff --git a/Kernel/arch/x86_64/mm_phys.c b/Kernel/arch/x86_64/mm_phys.c index 6955505d..fcc85473 100644 --- a/Kernel/arch/x86_64/mm_phys.c +++ b/Kernel/arch/x86_64/mm_phys.c @@ -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 diff --git a/Kernel/arch/x86_64/proc.c b/Kernel/arch/x86_64/proc.c index 8691100c..06c7d85d 100644 --- a/Kernel/arch/x86_64/proc.c +++ b/Kernel/arch/x86_64/proc.c @@ -287,10 +287,10 @@ void ArchThreads_Init(void) #if USE_MP } for(pos=0;pos 0 ) { + Log_Warning("ELF", "Elf_Relocate: No Dynamic symbol table, but count >0"); + return 0; + } // Alter Symbols to true base for(i = 0; i < iSymCount; i ++) @@ -409,7 +413,7 @@ int Elf_Relocate(void *Base) for( i = 0; i < j; i++ ) { ptr = (void*)(iBaseDiff + rela[i].r_offset); - if( !Elf_Int_DoRelocate(rel[i].r_info, ptr, rela[i].r_addend, dynsymtab, (Uint)Base) ) { + if( !Elf_Int_DoRelocate(rela[i].r_info, ptr, rela[i].r_addend, dynsymtab, (Uint)Base) ) { bFailed = 1; } } @@ -451,8 +455,8 @@ int Elf_Relocate(void *Base) return 0; } - LEAVE('x', hdr->entrypoint); - return hdr->entrypoint; + LEAVE('x', 1); + return 1; } /** diff --git a/Kernel/binary.c b/Kernel/binary.c index 0f5183c0..58d86d77 100644 --- a/Kernel/binary.c +++ b/Kernel/binary.c @@ -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'); diff --git a/Kernel/drv/iocache.c b/Kernel/drv/iocache.c index ba822df8..774c4974 100644 --- a/Kernel/drv/iocache.c +++ b/Kernel/drv/iocache.c @@ -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) diff --git a/Kernel/drv/proc.c b/Kernel/drv/proc.c index 0d1ae529..80561147 100644 --- a/Kernel/drv/proc.c +++ b/Kernel/drv/proc.c @@ -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) diff --git a/Kernel/heap.c b/Kernel/heap.c index a9e9931f..fc99f56c 100644 --- a/Kernel/heap.c +++ b/Kernel/heap.c @@ -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 ); diff --git a/Kernel/system.c b/Kernel/system.c index 1726fef2..66f645f2 100644 --- a/Kernel/system.c +++ b/Kernel/system.c @@ -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 { diff --git a/Kernel/threads.c b/Kernel/threads.c index 4ab76ff6..fa6f6e0f 100644 --- a/Kernel/threads.c +++ b/Kernel/threads.c @@ -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 diff --git a/Modules/IPStack/routing.c b/Modules/IPStack/routing.c index c37e7441..63793027 100644 --- a/Modules/IPStack/routing.c +++ b/Modules/IPStack/routing.c @@ -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) ) { diff --git a/Modules/IPStack/udp.c b/Modules/IPStack/udp.c index 6f3abc60..9e54701f 100644 --- a/Modules/IPStack/udp.c +++ b/Modules/IPStack/udp.c @@ -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; } diff --git a/Modules/Storage/FDD/fdd.c b/Modules/Storage/FDD/fdd.c index 801f2eb7..42150a95 100644 --- a/Modules/Storage/FDD/fdd.c +++ b/Modules/Storage/FDD/fdd.c @@ -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]; diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index 807527b1..4378d1db 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -145,7 +145,7 @@ int main(int argc, char *argv[], char *envp[]) } } -#if USE_READLINE +#if !USE_READLINE /** * \fn char *ReadCommandLine(int *Length) * \brief Read from the command line