TheLinx / lao

A library for audio output through Lua.
http://thelinx.github.com/lao/
18 stars 2 forks source link

strndup in l_play() ? #3

Closed peterbillam closed 7 years ago

peterbillam commented 10 years ago

Greetings again; in lao.c, l_play(lua_State L) tries to duplicate the samples:: char buffer = strndup(samples, num_bytes); but http://linux.die.net/man/3/strndup says: The strndup() function is similar, but ONLY COPIES AT MOST n bytes. If s is longer than n, only n bytes are copied, and a terminating null byte ('\0') is added. and I found ao_example.lua just played random noise and garbage :-(

But if I play the samples directly: int result = ao_play(dev, samples, num_bytes); then gcc warns me that I'm discarding a const qualifier, but ao_example.lua plays me a nice sine wave :-)

It's hard to believe that this has ever worked; so if the user base is small, it might be OK to change the API from require("ao") to local ao = require("ao"), see previous issue...

Regards, Peter

bartbes commented 10 years ago

Right, it should probably be num_bytes+1. And I'm fairly sure it has worked, though you're probably right about the userbase being small.

bartbes commented 10 years ago

Though honestly, this should probably a malloc+memcpy anyway, it's not a string and shouldn't be treated as such.