From d1363991a8f1f7ad5079fab05d16c18c8827c166 Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Fri, 12 Sep 2008 04:28:09 +0000 Subject: [PATCH] Fixed CID 1299: the char* name was used in a call to strtoul on line 1220 before being NULL checked on line 1234. I moved the null check to be after name is initialized and removed it from line 1234. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27428 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/thread.cpp | 45 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/src/system/kernel/thread.cpp b/src/system/kernel/thread.cpp index 2187757e42..78ea1be852 100644 --- a/src/system/kernel/thread.cpp +++ b/src/system/kernel/thread.cpp @@ -1218,31 +1218,32 @@ dump_thread_info(int argc, char **argv) for (; argi < argc; argi++) { const char *name = argv[argi]; - int32 id = strtoul(name, NULL, 0); + if (name != NULL) { + int32 id = strtoul(name, NULL, 0); - if (IS_KERNEL_ADDRESS(id)) { - // semi-hack - _dump_thread_info((struct thread *)id, shortInfo); - continue; - } - - // walk through the thread list, trying to match name or id - bool found = false; - struct hash_iterator i; - hash_open(sThreadHash, &i); - struct thread *thread; - while ((thread = (struct thread*)hash_next(sThreadHash, &i)) != NULL) { - if ((name != NULL && !strcmp(name, thread->name)) - || thread->id == id) { - _dump_thread_info(thread, shortInfo); - found = true; - break; + if (IS_KERNEL_ADDRESS(id)) { + // semi-hack + _dump_thread_info((struct thread *)id, shortInfo); + continue; } - } - hash_close(sThreadHash, &i, false); - if (!found) - kprintf("thread \"%s\" (%ld) doesn't exist!\n", name, id); + // walk through the thread list, trying to match name or id + bool found = false; + struct hash_iterator i; + hash_open(sThreadHash, &i); + struct thread *thread; + while ((thread = (struct thread*)hash_next(sThreadHash, &i)) != NULL) { + if (!strcmp(name, thread->name) || thread->id == id) { + _dump_thread_info(thread, shortInfo); + found = true; + break; + } + } + hash_close(sThreadHash, &i, false); + + if (!found) + kprintf("thread \"%s\" (%ld) doesn't exist!\n", name, id); + } } return 0;