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

RawSet accepts nil keys #319

Open
2 tasks done
frioux opened this issue May 5, 2021 · 0 comments
Open
2 tasks done

RawSet accepts nil keys #319

frioux opened this issue May 5, 2021 · 0 comments

Comments

@frioux
Copy link

frioux commented May 5, 2021

  • GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
  • GopherLua is a Lua5.1 implementation. In Lua, to keep it simple, it is more important to remove functionalities rather than to add functionalities unlike other languages . If you are going to introduce some new cool functionalities into the GopherLua code base and the functionalities can be implemented by existing APIs, It should be implemented as a library.

Please answer the following before submitting your issue:

  1. What version of GopherLua are you using? : ee81675
  2. What version of Go are you using? : 1.16
  3. What operating system and processor architecture are you using? : ubuntu
  4. What did you do? : (accidentally) called lua.LTable.RawSet with a nil key
  5. What did you expect to see? : a panic
  6. What did you see instead? : a silently corrupted table

The C API doesn't work this way; try this:

#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <stdio.h>

int
main(void)
{
    lua_State *L;
    L = luaL_newstate();

    luaL_openlibs(L);
    lua_getglobal(L, "_G");
    lua_pushnil(L);
    lua_pushliteral(L, "whatever");
    lua_rawset(L, -3);

    lua_close(L);

    return 0;
}

h/t to @hoelzro for helping me verify this

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

No branches or pull requests

1 participant