From: Lawrence S. <ljs...@us...> - 2013-06-07 04:59:11
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via efa97a42bbeaddb58b975d1ac67c28a42004d929 (commit) from 09fa80dfbd971a96127cb34827b87c8321e993c6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit efa97a42bbeaddb58b975d1ac67c28a42004d929 Author: Lawrence Sebald <ljs...@us...> Date: Fri Jun 7 00:58:21 2013 -0400 Begone pointless unsigned comparisons against 0 (namely >= 0 and < 0 tests). ----------------------------------------------------------------------- Summary of changes: kernel/arch/dreamcast/fs/fs_iso9660.c | 33 +++++++++--- kernel/arch/dreamcast/hardware/pvr/pvr_scene.c | 8 ++-- kernel/arch/dreamcast/sound/snd_mem.c | 4 +- kernel/fs/fs_ramdisk.c | 65 ++++++++++++++++------- kernel/fs/fs_romdisk.c | 30 ++++++++--- 5 files changed, 99 insertions(+), 41 deletions(-) diff --git a/kernel/arch/dreamcast/fs/fs_iso9660.c b/kernel/arch/dreamcast/fs/fs_iso9660.c index b808628..c1690c1 100644 --- a/kernel/arch/dreamcast/fs/fs_iso9660.c +++ b/kernel/arch/dreamcast/fs/fs_iso9660.c @@ -4,7 +4,7 @@ Copyright (C) 2000, 2001, 2003 Dan Potter Copyright (C) 2001 Andrew Kieschnick Copyright (C) 2002 Bero - Copyright (C) 2012 Lawrence Sebald + Copyright (C) 2012, 2013 Lawrence Sebald */ @@ -195,7 +195,7 @@ static uint32 iso_733(const uint8 *from) { this cache. As the cache fills up, sectors are removed from the end of it. */ typedef struct { - int32 sector; /* CD sector */ + uint32 sector; /* CD sector */ uint8 data[2048]; /* Sector data */ } cache_block_t; @@ -214,7 +214,7 @@ static void bclear_cache(cache_block_t **cache) { mutex_lock(&cache_mutex); for(i = 0; i < NUM_CACHE_BLOCKS; i++) - cache[i]->sector = -1; + cache[i]->sector = (uint32)-1; mutex_unlock(&cache_mutex); } @@ -257,7 +257,7 @@ static int bread_cache(cache_block_t **cache, uint32 sector) { /* If not, look for an open cache slot; if we find one, use it */ for(i = 0; i < NUM_CACHE_BLOCKS; i++) { - if(cache[i]->sector == -1) break; + if(cache[i]->sector == (uint32)-1) break; } /* If we didn't find one, kick an LRU block out of cache */ @@ -725,27 +725,46 @@ static off_t iso_seek(void * h, off_t offset, int whence) { file_t fd = (file_t)h; /* Check that the fd is valid */ - if(fd >= MAX_ISO_FILES || fh[fd].first_extent == 0 || fh[fd].broken) + if(fd >= MAX_ISO_FILES || fh[fd].first_extent == 0 || fh[fd].broken) { + errno = EBADF; return -1; + } /* Update current position according to arguments */ switch(whence) { case SEEK_SET: + if(offset < 0) { + errno = EINVAL; + return -1; + } + fh[fd].ptr = offset; break; + case SEEK_CUR: + if(offset < 0 && ((uint32)-offset) > fh[fd].ptr) { + errno = EINVAL; + return -1; + } + fh[fd].ptr += offset; break; + case SEEK_END: + if(offset < 0 && ((uint32)-offset) > fh[fd].size) { + errno = EINVAL; + return -1; + } + fh[fd].ptr = fh[fd].size + offset; break; + default: + errno = EINVAL; return -1; } /* Check bounds */ - if(fh[fd].ptr < 0) fh[fd].ptr = 0; - if(fh[fd].ptr > fh[fd].size) fh[fd].ptr = fh[fd].size; return fh[fd].ptr; diff --git a/kernel/arch/dreamcast/hardware/pvr/pvr_scene.c b/kernel/arch/dreamcast/hardware/pvr/pvr_scene.c index f560bcf..c649967 100644 --- a/kernel/arch/dreamcast/hardware/pvr/pvr_scene.c +++ b/kernel/arch/dreamcast/hardware/pvr/pvr_scene.c @@ -30,7 +30,7 @@ void * pvr_set_vertbuf(pvr_list_t list, void * buffer, int len) { assert(pvr_state.dma_mode); // Make sure it's a valid list. - assert(list >= 0 && list < PVR_OPB_COUNT); + assert(list < PVR_OPB_COUNT); // Make sure it's an _enabled_ list. assert(pvr_state.lists_enabled & (1 << list)); @@ -59,7 +59,7 @@ void * pvr_vertbuf_tail(pvr_list_t list) { uint8 * bufbase; // Check the validity of the request. - assert(list >= 0 && list < PVR_OPB_COUNT); + assert(list < PVR_OPB_COUNT); assert(pvr_state.dma_mode); // Get the buffer base. @@ -74,7 +74,7 @@ void pvr_vertbuf_written(pvr_list_t list, uint32 amt) { uint32 val; // Check the validity of the request. - assert(list >= 0 && list < PVR_OPB_COUNT); + assert(list < PVR_OPB_COUNT); assert(pvr_state.dma_mode); // Change the current end of the buffer. @@ -149,7 +149,7 @@ int pvr_list_begin(pvr_list_t list) { #endif /* !NDEBUG */ /* If we already had a list open, close it first */ - if(pvr_state.list_reg_open != -1 && pvr_state.list_reg_open != list) + if(pvr_state.list_reg_open != -1 && pvr_state.list_reg_open != (int)list) pvr_list_finish(); /* Ok, set the flag */ diff --git a/kernel/arch/dreamcast/sound/snd_mem.c b/kernel/arch/dreamcast/sound/snd_mem.c index d20b653..28054ac 100644 --- a/kernel/arch/dreamcast/sound/snd_mem.c +++ b/kernel/arch/dreamcast/sound/snd_mem.c @@ -117,12 +117,10 @@ void snd_mem_shutdown() { /* Allocate a chunk of SPU RAM; we will return an offset into SPU RAM. */ uint32 snd_mem_malloc(size_t size) { snd_block_t *e, *best = NULL; - int best_size = 4 * 1024 * 1024; + size_t best_size = 4 * 1024 * 1024; assert_msg(initted, "Use of snd_mem_malloc before snd_mem_init"); - assert(size >= 0); - if(size == 0) return 0; diff --git a/kernel/fs/fs_ramdisk.c b/kernel/fs/fs_ramdisk.c index fe260e1..043f341 100644 --- a/kernel/fs/fs_ramdisk.c +++ b/kernel/fs/fs_ramdisk.c @@ -1,8 +1,8 @@ /* KallistiOS ##version## fs_ramdisk.c - Copyright (C) 2002,2003 Dan Potter - Copyright (C) 2012 Lawrence Sebald + Copyright (C) 2002, 2003 Dan Potter + Copyright (C) 2012, 2013 Lawrence Sebald */ @@ -432,30 +432,55 @@ static off_t ramdisk_seek(void * h, off_t offset, int whence) { mutex_lock(&rd_mutex); /* Check that the fd is valid */ - if(fd < MAX_RAM_FILES && fh[fd].file != NULL && !fh[fd].dir) { - /* Update current position according to arguments */ - switch(whence) { - case SEEK_SET: - fh[fd].ptr = offset; - break; - case SEEK_CUR: - fh[fd].ptr += offset; - break; - case SEEK_END: - fh[fd].ptr = fh[fd].file->size + offset; - break; - default: + if(fd >= MAX_RAM_FILES || !fh[fd].file || fh[fd].dir) { + errno = EBADF; + mutex_unlock(&rd_mutex); + return -1; + } + + /* Update current position according to arguments */ + switch(whence) { + case SEEK_SET: + if(offset < 0) { + errno = EINVAL; + mutex_unlock(&rd_mutex); return -1; - } + } - /* Check bounds */ - if(fh[fd].ptr < 0) fh[fd].ptr = 0; + fh[fd].ptr = offset; + break; - if(fh[fd].ptr > fh[fd].file->size) fh[fd].ptr = fh[fd].file->size; + case SEEK_CUR: + if(offset < 0 && ((uint32)-offset) > fh[fd].ptr) { + errno = EINVAL; + mutex_unlock(&rd_mutex); + return -1; + } - rv = fh[fd].ptr; + fh[fd].ptr += offset; + break; + + case SEEK_END: + if(offset < 0 && ((uint32)-offset) > fh[fd].file->size) { + errno = EINVAL; + mutex_unlock(&rd_mutex); + return -1; + } + + fh[fd].ptr = fh[fd].file->size + offset; + break; + + default: + errno = EINVAL; + mutex_unlock(&rd_mutex); + return -1; } + /* Check bounds */ + // XXXX: Technically this isn't correct. Fix it sometime. + if(fh[fd].ptr > fh[fd].file->size) fh[fd].ptr = fh[fd].file->size; + + rv = fh[fd].ptr; mutex_unlock(&rd_mutex); return rv; } diff --git a/kernel/fs/fs_romdisk.c b/kernel/fs/fs_romdisk.c index 35f2779..caef7f3 100644 --- a/kernel/fs/fs_romdisk.c +++ b/kernel/fs/fs_romdisk.c @@ -1,8 +1,8 @@ /* KallistiOS ##version## fs_romdisk.c - Copyright (C) 2001,2002,2003 Dan Potter - Copyright (C) 2012 Lawrence Sebald + Copyright (C) 2001, 2002, 2003 Dan Potter + Copyright (C) 2012, 2013 Lawrence Sebald */ @@ -95,7 +95,7 @@ static mutex_t fh_mutex; /* Given a filename and a starting romdisk directory listing (byte offset), search for the entry in the directory and return the byte offset to its entry. */ -static uint32 romdisk_find_object(rd_image_t * mnt, const char *fn, int fnlen, int dir, uint32 offset) { +static uint32 romdisk_find_object(rd_image_t * mnt, const char *fn, size_t fnlen, int dir, uint32 offset) { uint32 i, ni, type; const romdisk_file_t *fhdr; @@ -132,7 +132,6 @@ static uint32 romdisk_find_object(rd_image_t * mnt, const char *fn, int fnlen, i /* Check filename */ if((strlen(fhdr->filename) == fnlen) && (!strncasecmp(fhdr->filename, fn, fnlen))) { - /* Match: return this index */ return i; } @@ -279,28 +278,45 @@ static off_t romdisk_seek(void * h, off_t offset, int whence) { /* Check that the fd is valid */ if(fd >= MAX_RD_FILES || fh[fd].index == 0 || fh[fd].dir) { - errno = EINVAL; + errno = EBADF; return -1; } /* Update current position according to arguments */ switch(whence) { case SEEK_SET: + if(offset < 0) { + errno = EINVAL; + return -1; + } + fh[fd].ptr = offset; break; + case SEEK_CUR: + if(offset < 0 && ((uint32)-offset) > fh[fd].ptr) { + errno = EINVAL; + return -1; + } + fh[fd].ptr += offset; break; + case SEEK_END: + if(offset < 0 && ((uint32)-offset) > fh[fd].size) { + errno = EINVAL; + return -1; + } + fh[fd].ptr = fh[fd].size + offset; break; + default: + errno = EINVAL; return -1; } /* Check bounds */ - if(fh[fd].ptr < 0) fh[fd].ptr = 0; - if(fh[fd].ptr > fh[fd].size) fh[fd].ptr = fh[fd].size; return fh[fd].ptr; hooks/post-receive -- A pseudo Operating System for the Dreamcast. |