diff --git a/kafka/producer.c b/kafka/producer.c index 3bb7375..f3e2cc0 100644 --- a/kafka/producer.c +++ b/kafka/producer.c @@ -332,19 +332,19 @@ lua_producer_produce(struct lua_State *L) { lua_pushstring(L, "key"); lua_gettable(L, -2 ); + size_t key_len; // rd_kafka will copy key so no need to worry about this cast - char *key = (char *)lua_tostring(L, -1); - lua_pop(L, 1); + char *key = (char *)lua_tolstring(L, -1, &key_len); - size_t key_len = key != NULL ? strlen(key) : 0; + lua_pop(L, 1); lua_pushstring(L, "value"); lua_gettable(L, -2 ); + size_t value_len; // rd_kafka will copy value so no need to worry about this cast - char *value = (char *)lua_tostring(L, -1); - lua_pop(L, 1); + char *value = (char *)lua_tolstring(L, -1, &value_len); - size_t value_len = value != NULL ? strlen(value) : 0; + lua_pop(L, 1); if (key == NULL && value == NULL) { int fail = safe_pushstring(L, "producer message must contains non nil key or value");