Out-params and arrays are raw pointers #10
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Functions that return a count or an array through a pointer force the caller to allocate a buffer
and read it back. Some array inputs are wrapped in a one-element buffer and then passed with a
larger count, which reads out of bounds.
Current behavior
SetWindowIconsis worse (hate-no-d.lua:3328): it allocatesImage[1]and passescount.raylib loops
for (i = 0; i < count; i++) images[i], socount > 1reads past the buffer.Functions affected
24 functions need declarations, not special cases:
LoadFileData,CompressData,DecompressData,EncodeDataBase64,DecodeDataBase64,ExportImageToMemoryLoadImagePalette,LoadFontData,LoadMaterials,LoadModelAnimationsLoadTextLines,TextSplitLoadCodepointsGetCodepoint*(3),QuaternionToAxisAngle,rlGenTextureMipmaps,rlGetGlTextureFormats(3),MatrixDecompose(3),CheckCollisionLinesTextAppend(position)LoadImageAnim*TextCopy(writable buffer),rlSetShader,SetWindowIcons, allUnload*Proposal
1. Declare it
Two tables in the generator: one maps a parameter index to
outorinout, the other maps thereturn shape to its freeing function.
2. Keep old calls working
Out-params stay in the signature as optional arguments. If the caller passes a buffer, forward it
and return exactly what the C function returns, as today. If not, use a reused slot (issue 05),
convert, and return the values:
3. Return the useful shape
bytesintscarraylinesUnloadTextLines(p, n);TextSplitis staticTwo loaders have no count out-param: derive it (
LoadImageColors=width * height,LoadWaveSamples=frameCount * channels) and append it as a second return value.4. Accept arrays properly
For
T *x, int countinputs: accept a Lua table (converted), a cdata array, or a single struct.Default
countto#tableand reject a count larger than the table. Return nothing.5. Warn on anything new
Sweep all non-const pointer params that are in neither
PARAM_DIRnor an input allowlist. Warn;never fail the build, so a raylib bump cannot break generation.
Acceptance criteria
LoadFileDataround-trips 4 KiB of random bytes, returns the right size, and does not leak.\0.LoadTextLinesreturns{"a","b","c"}; a secondTextSplitdoes not corrupt the first.CheckCollisionLinesreturnsfalse, nilwhen segments do not cross.SetWindowIconswith three images does not crash.make check-bindingspasses.Notes
LoadMaterialshas no unload function in raylib; free the array withMemFreeand document it.carrayresults are armed by gc-hooks, so a forgotten unload is safe; an explicitUnload*disarms the finalizer.TextSplitreuses static storage, so the strings must be copied before returning.