Skip to content

Commit

Permalink
Fix issues found in fsqlf_format_bytes()
Browse files Browse the repository at this point in the history
Actual issues were in print_kw() and print_nonkw_text(),
which always wrote to the start of the buffer.
(they have to increment 'start' of the text each time)
  • Loading branch information
dnsmkl committed Feb 23, 2016
1 parent 6bfae31 commit fd1303c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib_fsqlf/formatter/print_keywords.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,11 @@ static void print_kw(
assert(bout->buffer);
bout->len_alloc = len_realloc;
}
strncpy(bout->buffer, spacing_txt, len_spacing);
strncpy(bout->buffer, text, len_text);
strncpy(bout->buffer + bout->len_used, spacing_txt, len_spacing);
bout->len_used += len_spacing;
strncpy(bout->buffer + bout->len_used, text, len_text);
bout->len_used += len_text;
bout->buffer[bout->len_used] = '\0';
}

free(spacing_txt);
Expand Down Expand Up @@ -267,8 +270,11 @@ static void print_nonkw_text(
assert(bout->buffer);
bout->len_alloc = len_realloc;
}
strncpy(bout->buffer, spacing_txt, len_spacing);
strncpy(bout->buffer, txtdup, len_text);
strncpy(bout->buffer + bout->len_used, spacing_txt, len_spacing);
bout->len_used += len_spacing;
strncpy(bout->buffer + bout->len_used, txtdup, len_text);
bout->len_used += len_text;
bout->buffer[bout->len_used] = '\0';
}

free(txtdup);
Expand Down
6 changes: 6 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,13 @@ $(EXEC_CLI): $(COBJ) $(LIBNAME)
$(CC) $(CFLAGS) $(COBJ) -L. -lfsqlf -Wl,-rpath,. -o $@
# strip $@

testcases/test_fsqlf_format_bytes: testcases/test_fsqlf_format_bytes.o
$(CC) $(CFLAGS) $< -L. -lfsqlf -Wl,-rpath,. -o $@

testcases/test_fsqlf_format_bytes.o: testcases/test_fsqlf_format_bytes.c
$(CC) $(CFLAGS) -c $< -o $@

newtest: testcases/test_fsqlf_format_bytes

#
# BUILD GUI
Expand Down

0 comments on commit fd1303c

Please sign in to comment.