creationix / dukluv

LibUV bindings for duktape JS engine
http://dukluv.io
MIT License
266 stars 36 forks source link

check for NULL when parsing strings #4

Closed JerrySievert closed 9 years ago

JerrySievert commented 9 years ago

to reproduce the issue:

$ build/duklub repl.js
fd = uv.fs_open('./b.js', 'r', 0644);
uv.fs_read(fd, 1024, 0).toString();

before the change, an error trying to parse an empty string (NULL), after the change, expected behavior.

JerrySievert commented 9 years ago

i'd still recommend checking for the validity of the pointer for 0 or pointer overflows, just to be safe, then checking against *buffer or as you'd like buffer[0] (both amount to the same thing, but are coding style).

i'll happily change the second part if you'd prefer.

creationix commented 9 years ago

Sounds good, change the style to be more consistent with the rest of the code and I'll take it. I doubt the one extra null check will hurt any real performance.