Skip to content

Commit

Permalink
fix overflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jwerle committed Mar 9, 2016
1 parent f746933 commit 37fe659
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 49 deletions.
1 change: 0 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ SRC := $(wildcard ../deps/*/*.c)
TARGETS += grid
TARGETS += cube
TARGETS += bunny
TARGETS += cube-orbit

CFLAGS += -I ../include
CFLAGS += -I ../deps
Expand Down
2 changes: 1 addition & 1 deletion include/glisy/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct glisy_buffer {
GLuint size;
GLuint usage;
GLuint handle;
GLfloat data[BUFSIZ];
GLvoid *data;
};

/**
Expand Down
4 changes: 2 additions & 2 deletions include/glisy/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

typedef struct glisy_color glisy_color;
struct glisy_color {
char name[BUFSIZ];
char string[BUFSIZ];
char *name;
char *string;
double r, g, b, a;
uint32_t value;
};
Expand Down
4 changes: 2 additions & 2 deletions include/glisy/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct glisy_geometry {
GLboolean dirty;
GLenum elementsType;
GLenum usage;
void *faces;
GLvoid *faces;
GLboolean useElements;
glisy_program *program;
};
Expand Down Expand Up @@ -81,7 +81,7 @@ void
glisy_geometry_faces(glisy_geometry *geometry,
GLenum type,
GLuint count,
void *indices);
GLvoid *indices);

/**
* This function clears out the members of a geometry and disposes of its VAO
Expand Down
2 changes: 0 additions & 2 deletions include/glisy/program.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@

typedef struct glisy_program glisy_program;
struct glisy_program {

// GL Program ID.
GLuint id;

};

/**
Expand Down
2 changes: 1 addition & 1 deletion include/glisy/shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ typedef struct glisy_shader glisy_shader;
struct glisy_shader {

// Shader GLSL source buffer.
char source[BUFSIZ];
char *source;

// Shader source type.
GLuint type;
Expand Down
4 changes: 2 additions & 2 deletions include/glisy/uniform.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ enum {
typedef struct glisy_uniform glisy_uniform;
struct glisy_uniform {
const char *name;
void *buffer;
GLvoid *buffer;
GLuint dimension;
GLint location;
GLsizei size;
Expand All @@ -34,6 +34,6 @@ void
glisy_uniform_bind(glisy_uniform *uniform, glisy_program *program);

void
glisy_uniform_set(glisy_uniform *uniform, void *data, GLsizei size);
glisy_uniform_set(glisy_uniform *uniform, GLvoid *data, GLsizei size);

#endif
2 changes: 1 addition & 1 deletion include/glisy/vao.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct glisy_vao_attribute {
const char *name;

struct {
void *data;
GLvoid *data;
GLuint type;
GLuint size;
GLuint usage;
Expand Down
3 changes: 1 addition & 2 deletions src/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,5 @@ glisy_buffer_source(glisy_buffer *buffer, GLsizei size, GLvoid *data) {
if (!buffer) return;
if (!data) return;
buffer->size = size;
memset(buffer->data, 0, BUFSIZ);
memcpy(buffer->data, data, size);
buffer->data = data;
}
14 changes: 7 additions & 7 deletions src/color.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,21 @@ glisy_color_init(glisy_color *color, const char *name, uint32_t value) {
uint32_t tmp;
if (!color) return;

if (!strlen(color->name)) {
memset(color->name, 0, BUFSIZ);
if (!color->name) {
color->name = "";
}

if (!strlen(color->string)) {
memset(color->string, 0, BUFSIZ);
if (!color->string) {
color->string = "";
}

if (name && value == 0) {
if ('#' == name[0]) {
strcat(color->string, name);
color->string = strdup(name);
} else if (name == strstr(name, "rgb")) {
strcat(color->string, name);
color->string = strdup(name);
} else {
strcat(color->name, name);
color->name = strdup(name);
}

short ok = 0;
Expand Down
48 changes: 22 additions & 26 deletions src/geometry.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#include <strings.h>
#include <glisy/program.h>
#include <glisy/geometry.h>

Expand All @@ -22,11 +21,9 @@ _upsert_attr(glisy_geometry *geometry, glisy_vao_attribute *attribute) {
if ((cursor->name && 0 == strcmp(cursor->name, attribute->name)) ||
(!cursor->name && cursor->location == attribute->location)) {
attribute->location = cursor->location;
memcpy(cursor->buffer.data,
attribute->buffer.data,
attribute->buffer.size);
#define copy(P) cursor-> P = attribute-> P;
copy(name);
copy(buffer.data);
copy(buffer.type);
copy(buffer.size);
copy(buffer.usage);
Expand Down Expand Up @@ -99,35 +96,34 @@ glisy_geometry_update(glisy_geometry *geometry) {
if (GL_TRUE != geometry->useElements) {
glisy_vao_update(&geometry->vao, 0);
} else {
// size of the vertex faces (faces * sizeof(elementsType))
GLsizei facesSize = geometry->faceslen * (
// assume GLushort if GL_UNSIGNED_SHORT
GL_UNSIGNED_SHORT == geometry->elementsType ?
sizeof(GLushort) :
// assume GLuint if GL_UNSIGNED_INT
GL_UNSIGNED_INT ?
sizeof(GLuint) :
// otherwise assume GL_UNSIGNED_SHORT as default
sizeof(GLushort));

glisy_vao_update(&geometry->vao, &geometry->index);
glGenBuffers(1, &ibo);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,
// size of the vertex faces (faces * sizeof(elementsType))
geometry->faceslen * (
// assume GLushort if GL_UNSIGNED_SHORT
GL_UNSIGNED_SHORT == geometry->elementsType ?
sizeof(GLushort) :
// assume GLuint if GL_UNSIGNED_INT
GL_UNSIGNED_INT ?
sizeof(GLuint) :
// otherwise assume GL_UNSIGNED_SHORT as default
sizeof(GLushort)
),

// geometry vertex faces (indices)
geometry->faces,
facesSize, geometry->faces,

// buffer initialization usage type that is one of:
// GL_ARRAY_BUFFER,
// GL_UNIFORM_BUFFER
// GL_TEXTURE_BUFFER,
// GL_COPY_READ_BUFFER,
// GL_PIXEL_PACK_BUFFER,
// GL_COPY_WRITE_BUFFER,
// GL_PIXEL_UNPACK_BUFFER,
// GL_ELEMENT_ARRAY_BUFFER,
// GL_TRANSFORM_FEEDBACK_BUFFER,
// GL_STREAM_DRAW
// GL_STREAM_READ
// GL_STREAM_COPY
// GL_STATIC_DRAW
// GL_STATIC_READ
// GL_STATIC_COPY
// GL_DYNAMIC_DRAW
// GL_DYNAMIC_READ
// GL_DYNAMIC_COPY
geometry->usage);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/shader.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ glisy_shader_init(glisy_shader *shader, GLuint type, const char *source) {
if (shader->id == 0) return GL_FALSE;

shader->type = type;
memset(shader->source, 0, BUFSIZ);
strcat(shader->source, source);
shader->source = strdup(source);

glShaderSource(shader->id, 1, &source, 0);
glCompileShader(shader->id);
Expand Down

0 comments on commit 37fe659

Please sign in to comment.