[Mono-list] Re: mono_string_null(NULL)
Wed, 09 Jan 2002 05:29:35 -0800 (PST)
Paolo Molaro wrote
> On 01/08/02 Matt Kimball wrote:
> > mono/metadata : ChangeLog object.c
> > Log message:
> > Tue Jan 8 22:47:44 EST 2002 Matt Kimball <email@example.com>
> > * object.c: mono_string_new should return a NULL when the string
> > passed in is NULL -- not try to deference it.
> I don't agree with this change: it will hide bugs in the code.
The reason I made this particular change was in response to the trampoline code
I just changed in arch/x86/tramp.c which manages strings returned by functions
in non-internal pinvoke'd calls. Before, when you tried to call
System.Private.Wrapper.readdir(), you'd soon crash the runtime because it would
assume that the char* returned was actually a pointer to an object. Now, it
will call mono_string_new() after the function returns to wrap the returned
string in a string object.
One problem was that if readdir() returns NULL (i.e. end-of-directory), it would
pass a NULL pointer into mono_string_new(), which would throw an exception in
response to the null pointer dereference. Obviously this is wrong -- readdir
should return NULL, now throw an exception. That's why I made that particular
Would it be better for to revert that change, and write a wrapper around
mono_string_new() which checks for NULLs, and use that wrapper in
arch/x86/tramp.c? (And, that way mono_string_new() would still throw an
exception on NULL).