server icon indicating copy to clipboard operation
server copied to clipboard

🐛 Crash using !exec (incorrectly?)

Open CatsEyeXI opened this issue 2 years ago • 4 comments

  • [x] I have paid attention to this example and will edit again if need be to not break the formatting, or I will be ignored
  • [x] I have searched existing issues to see if the issue has already been opened, and I have checked the commit log to see if the issue has been resolved since my server was last updated
  • [x] I have read and understood the Contributing Guide

Branch affected by issue

base

Steps to reproduce

I was asked to create a separate issue for this, but basically I erroneously sent an !exec print("%s", player:getMainJob()) (this would return an integer, not a string), but instead of getting an error, the server crashed.

Expected behavior

Expect to return an error?

CatsEyeXI avatar Jul 15 '22 04:07 CatsEyeXI

It certainly shouldn't crash, but out binding for print (we replace Lua's default print with our own) is only intended to stringify types and print them out:

https://github.com/LandSandBoat/server/blob/base/src/common/lua.cpp#L135

It doesn't handle format-style strings. In the rest of the codebase we'd do:

print(string.format("%s", player:getName()))

Still, leave this open and we'll have a snoop around and see if this is something we can fix

zach2good avatar Jul 15 '22 19:07 zach2good

(the crash, not the usage)

zach2good avatar Jul 15 '22 19:07 zach2good

I wouldn't be opposed to adding printf as an alias for print(string.format())

zach2good avatar Jul 16 '22 04:07 zach2good

I wouldn't be opposed to adding printf as an alias for print(string.format())

~~you mean change our existing one to that? coz we have a printf in lua already~~ https://github.com/LandSandBoat/server/blob/d2915bc03b3a2c3fa0ec5a2fa60f2e281137f1e4/scripts/globals/common.lua#L32

TeoTwawki avatar Jul 16 '22 04:07 TeoTwawki