This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Possible bug in dbg-threads-syscall.c
- From: "Patrick Doyle" <wpd at delcomsys dot com>
- To: "eCos" <ecos-discuss at sourceware dot cygnus dot com>
- Date: Tue, 27 Nov 2001 10:41:05 -0500
- Subject: [ECOS] Possible bug in dbg-threads-syscall.c
I believe that I have found a subtle bug in "dbg-threads-syscall.c", and I
would appreciate some feedback on this.
Here is the 'dbg_thread_syscall()' function. The problem is that, on the
surface, this looks correct, but in my particular environment, where
'dbg_thread_syscall()' is called when 'dbg_syscall_ptr' is NULL, things just
don't work.
static dbg_syscall_func * dbg_syscall_ptr ;
static __inline__ int dbg_thread_syscall(
enum dbg_syscall_ids id)
{
dbg_syscall_func f ; /* double indirect via */
if (0 ==(f = *dbg_syscall_ptr)) return 0 ; /* no pointer to vector */
if (0 == *f) return 0 ; /* vector not initialized */
return (*f)(id,&tcall);
}
Basically, 'f' dereferences the NULL pointer, getting a non-zero value, so
that the first test passes, then the contents of address to which 'f' points
is also non-zero, so the second test passes, so the final line gets invoked
and my program disappears into never-never-land. (Well, it would if I were
actually running it on real hardware, I actually tracked this down on the
simulator).
Anyway, here is my proposed patch, comments and feedback are definately
welcome :-)
(If this doesn't make it through the mail sanely, please send me an email
directly and I will forward the patch as an attachement -- it is very
simple).
--wpd
*** dbg-threads-syscall.c-orig Tue Nov 27 10:01:41 2001
--- dbg-threads-syscall.c-new Tue Nov 27 10:03:11 2001
***************
*** 82,89 ****
enum dbg_syscall_ids id)
{
dbg_syscall_func f ; /* double indirect via */
! if (0 ==(f = *dbg_syscall_ptr)) return 0 ; /* no pointer to vector */
! if (0 == *f) return 0 ; /* vector not initialized */
return (*f)(id,&tcall);
}
--- 82,89 ----
enum dbg_syscall_ids id)
{
dbg_syscall_func f ; /* double indirect via */
! if (0 == dbg_syscall_ptr) return 0 ; /* no pointer to vector */
! if (0 ==(f = *dbg_syscall_ptr)) return 0 ; /* vector not initialized */
return (*f)(id,&tcall);
}