Skip to content

strndump function implementation #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 30, 2012
Merged

Conversation

caiiiycuk
Copy link
Contributor

Add strndup function implementation (in src/library.js) and test for it (in runner.py). Also add Aleksandr Guraynov to the AUTHORS as said in wiki.

I dont know is this function exists on MacOS and Window. May be some checks need to be added.

@caiiiycuk
Copy link
Contributor Author

strndup in The Open Group Technical Standard: http://pubs.opengroup.org/onlinepubs/9699919799/functions/strndup.html

strndup: function(ptr, size) {
var len = String_len(ptr);

if (size <= 0 || size >= len) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the check <=0 might be wrong. If size is 0, but len is larger than 0, then what will happen here is we copy the entire original string. But we should copy 0 bytes of it, that is, just return a new string of size 0 (just a null terminator).

If I am not mistaken, just removing the size <= 0 condition will make this work ok. If size is 0, the processing after it will work ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You right. I will fix it. And when size < 0 i assume that strndup should also return empty string.

@caiiiycuk
Copy link
Contributor Author

Now problem with zero and negative size are fixed.

kripken added a commit that referenced this pull request May 30, 2012
strndump function implementation
@kripken kripken merged commit c055544 into emscripten-core:incoming May 30, 2012
@kripken
Copy link
Member

kripken commented May 30, 2012

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants