Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix #5

Merged
merged 3 commits into from
Feb 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vgs2mml
*.dSYM
test.bgm
test_memchk

4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## Version 1.02
- added '\0' terminated check
- bugfix: https://github.com/suzukiplan/vgs-mml-compiler/issues/3

## Version 1.01
- fixed compiler in UNIX: https://github.com/suzukiplan/vgs-mml-compiler/issues/1

Expand Down
7 changes: 4 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ CC=/usr/bin/gcc

all: vgs2mml

vgs2mml: src/vgsmml.c src/vgsmml.h src/cli.c vgs-bgm-decoder/src/vgsdec_internal.h
$(CC) -o vgs2mml -I./src -I./vgs-bgm-decoder/src src/vgsmml.c src/cli.c
vgs2mml: src/vgsmml.c src/vgsmml.h src/cli.c vgs-bgm-decoder/src/miniz.c vgs-bgm-decoder/src/vgsdec_internal.h
$(CC) -o vgs2mml -I./src -I./vgs-bgm-decoder/src src/vgsmml.c src/cli.c vgs-bgm-decoder/src/miniz.c

test: all
test "`./vgs2mml ./test/test-error-undefined-macro.mml test.bgm`" = "error(101) line=52: undeclared variable was specified"
./vgs2mml ./test/test-normal.mml test.bgm
vgs2play test.bgm
$(CC) -o test_memchk -I./src -I./vgs-bgm-decoder/src src/vgsmml.c test/test_memchk.c vgs-bgm-decoder/src/miniz.c
valgrind --tool=memcheck ./test_memchk

7 changes: 7 additions & 0 deletions src/vgsmml.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ struct VgsBgmData* __stdcall vgsmml_compile_from_memory(void* data, size_t size,
return NULL;
}

/* memory check */
if ('\0' != ((char*)data)[size - 1]) {
strcpy(err->message, "need specify the \'\\0\' terminated string to the data argument.");
err->code = VGSMML_ERR_INVALID;
return NULL;
}

/* count line */
for (nLine = 1, i = 0; buf[i]; i++) {
if ('\n' == buf[i]) nLine++;
Expand Down
17 changes: 17 additions & 0 deletions test/test_memchk.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
#include <string.h>
#include "vgsmml.h"

int main(int argc, char* argv[])
{
struct VgsMmlErrorInfo err;
char foo[4];
strcpy(foo, "foo");
if (NULL == vgsmml_compile_from_memory(foo, 3, &err) && VGSMML_ERR_INVALID == err.code) {
puts(err.message);
puts("test succeed");
return 0;
}
puts("test failed");
return -1;
}
2 changes: 1 addition & 1 deletion vgs-bgm-decoder