Skip to content
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

Fix eval command #1633

Merged
merged 2 commits into from
Nov 1, 2021
Merged

Fix eval command #1633

merged 2 commits into from
Nov 1, 2021

Conversation

technomancy
Copy link
Contributor

This fixes issue #800.

I am not 100% sure this is in line with the original intent of the fields, and I have very little C experience!

The CommandDesc struct has two relevant fields here: src and
command. The src field is supposed to contain the source of the entire
input while the command field is supposed to contain just the name of
the command being invoked; aka everything before the first space.

We would start with input like this:

eval trace("hello" .. "world")

What we want is:

src: eval trace("hello" .. "world")
command: eval

The src field was set to a copy of the input, and then the command
field was set to running strtok on src to find the first space. But
even though strtok returns what looks like a string, it's actually
just pointing to the same copy of src which now happens to have been
terminated right where the first space used to be.

So what we got was just:

src: eval
command: eval

The fix is to copy the input into src and command fields separately
and only call strtok on command, allowing src to be left alone.

The CommandDesc struct has two relevant fields here: src and
command. The src field is supposed to contain the source of the entire
input while the command field is supposed to contain just the name of
the command being invoked; aka everything before the first space.

We would start with input like this:

    eval trace("hello" .. "world")

What we want is:

   src: eval trace("hello" .. "world")
   command: eval

The src field was set to a copy of the input, and then the command
field was set to running strtok on src to find the first space. But
even though strtok returns what looks like a string, it's actually
just pointing to the same copy of src which now happens to have been
terminated right where the first space used to be.

So what we got was just:

   src: eval
   command: eval

The fix is to copy the input into src and command fields separately
and only call strtok on command, allowing src to be left alone.

Finally since src and command are now separate strings we must free
them separately rather than only freeing src.
Previously we used parsed params which was incorrect and stopped at
the first space.
Copy link
Owner

@nesbox nesbox left a comment

Choose a reason for hiding this comment

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

Thank you.

@nesbox nesbox merged commit 8c6aecf into nesbox:master Nov 1, 2021
@nesbox nesbox linked an issue Nov 1, 2021 that may be closed by this pull request
@technomancy technomancy deleted the fix-eval-command branch June 1, 2024 05:00
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.

Eval nonfunctional?
2 participants