From 79083c7df1dede597e3c2e9264794f198c2ae77e Mon Sep 17 00:00:00 2001 From: bjorn Date: Tue, 11 Jun 2019 19:57:20 -0700 Subject: [PATCH] Fix warnings on newer versions of gcc; --- src/api/l_canvas.c | 2 +- src/api/l_graphics.c | 4 ++-- src/api/l_mesh.c | 6 +++--- src/core/ref.h | 2 +- src/lib/vec/vec.h | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/api/l_canvas.c b/src/api/l_canvas.c index 1282aec5..7f1ac1bb 100644 --- a/src/api/l_canvas.c +++ b/src/api/l_canvas.c @@ -55,7 +55,7 @@ static int l_lovrCanvasNewTextureData(lua_State* L) { uint32_t index = luaL_optinteger(L, 2, 1) - 1; uint32_t count; lovrCanvasGetAttachments(canvas, &count); - lovrAssert(index >= 0 && index < count, "Can not create a TextureData from Texture #%d of Canvas (it only has %d textures)", index, count); + lovrAssert(index < count, "Can not create a TextureData from Texture #%d of Canvas (it only has %d textures)", index, count); TextureData* textureData = lovrCanvasNewTextureData(canvas, index); luax_pushtype(L, TextureData, textureData); lovrRelease(TextureData, textureData); diff --git a/src/api/l_graphics.c b/src/api/l_graphics.c index a9edf1c8..e164e7ca 100644 --- a/src/api/l_graphics.c +++ b/src/api/l_graphics.c @@ -1538,11 +1538,11 @@ static int l_lovrGraphicsNewTexture(lua_State* L) { lua_pop(L, 1); lua_getfield(L, index, "type"); - type = lua_isnil(L, -1) ? type : luaL_checkoption(L, -1, NULL, TextureTypes); + type = lua_isnil(L, -1) ? type : (TextureType) luaL_checkoption(L, -1, NULL, TextureTypes); lua_pop(L, 1); lua_getfield(L, index, "format"); - format = lua_isnil(L, -1) ? format : luaL_checkoption(L, -1, NULL, TextureFormats); + format = lua_isnil(L, -1) ? format : (TextureFormat) luaL_checkoption(L, -1, NULL, TextureFormats); lua_pop(L, 1); lua_getfield(L, index, "msaa"); diff --git a/src/api/l_mesh.c b/src/api/l_mesh.c index 80c5ae36..a3a09e5e 100644 --- a/src/api/l_mesh.c +++ b/src/api/l_mesh.c @@ -174,7 +174,7 @@ static int l_lovrMeshGetVertex(lua_State* L) { static int l_lovrMeshSetVertex(lua_State* L) { Mesh* mesh = luax_checktype(L, 1, Mesh); uint32_t index = luaL_checkinteger(L, 2) - 1; - lovrAssert(index >= 0 && index < lovrMeshGetVertexCount(mesh), "Invalid mesh vertex index: %d", index + 1); + lovrAssert(index < lovrMeshGetVertexCount(mesh), "Invalid mesh vertex index: %d", index + 1); bool table = lua_istable(L, 3); if (!mesh->vertexBuffer || mesh->attributeCount == 0 || mesh->attributes[0].buffer != mesh->vertexBuffer) { @@ -222,7 +222,7 @@ static int l_lovrMeshGetVertexAttribute(lua_State* L) { uint32_t attributeIndex = luaL_checkinteger(L, 3) - 1; Buffer* buffer = lovrMeshGetVertexBuffer(mesh); lovrAssert(lovrBufferIsReadable(buffer), "Mesh:getVertex can only be used if the Mesh was created with the readable flag"); - lovrAssert(vertexIndex >= 0 && vertexIndex < lovrMeshGetVertexCount(mesh), "Invalid mesh vertex: %d", vertexIndex + 1); + lovrAssert(vertexIndex < lovrMeshGetVertexCount(mesh), "Invalid mesh vertex: %d", vertexIndex + 1); lovrAssert(attributeIndex < mesh->attributeCount, "Invalid mesh attribute: %d", attributeIndex + 1); lovrAssert(mesh->attributes[attributeIndex].buffer == mesh->vertexBuffer, "Invalid mesh attribute: %d", attributeIndex + 1); MeshAttribute* attribute = &mesh->attributes[attributeIndex]; @@ -246,7 +246,7 @@ static int l_lovrMeshSetVertexAttribute(lua_State* L) { uint32_t vertexIndex = luaL_checkinteger(L, 2) - 1; uint32_t attributeIndex = luaL_checkinteger(L, 3) - 1; bool table = lua_istable(L, 4); - lovrAssert(vertexIndex >= 0 && vertexIndex < lovrMeshGetVertexCount(mesh), "Invalid mesh vertex: %d", vertexIndex + 1); + lovrAssert(vertexIndex < lovrMeshGetVertexCount(mesh), "Invalid mesh vertex: %d", vertexIndex + 1); lovrAssert(attributeIndex < mesh->attributeCount, "Invalid mesh attribute: %d", attributeIndex + 1); lovrAssert(mesh->attributes[attributeIndex].buffer == mesh->vertexBuffer, "Invalid mesh attribute: %d", attributeIndex + 1); MeshAttribute* attribute = &mesh->attributes[attributeIndex]; diff --git a/src/core/ref.h b/src/core/ref.h index f8eb80a1..1490aecc 100644 --- a/src/core/ref.h +++ b/src/core/ref.h @@ -28,6 +28,6 @@ static inline uint32_t ref_dec(Ref* ref) { return --*ref; } void* _lovrAlloc(size_t size); #define toRef(o) (Ref*) (o) - 1 #define lovrAlloc(T) (T*) _lovrAlloc(sizeof(T)) -#define lovrRetain(o) o && !ref_inc(toRef(o)) +#define lovrRetain(o) if (o && !ref_inc(toRef(o))) { lovrThrow("Refcount overflow in %s:%d", __FILE__, __LINE__); } #define lovrRelease(T, o) if (o && !ref_dec(toRef(o))) lovr ## T ## Destroy(o), free(toRef(o)); #define _lovrRelease(o, f) if (o && !ref_dec(toRef(o))) f(o), free(toRef(o)); diff --git a/src/lib/vec/vec.h b/src/lib/vec/vec.h index 2430611e..0c0cb3cf 100644 --- a/src/lib/vec/vec.h +++ b/src/lib/vec/vec.h @@ -33,7 +33,7 @@ #define vec_push(v, val)\ ( vec_expand_(vec_unpack_(v)) ? -1 :\ - ((v)->data[(v)->length++] = (val), 0), 0 ) + ((v)->data[(v)->length++] = (val), 0) ) #define vec_pop(v)\