Fix the bug I was crying about in the last commit
It was a pretty simple fix. I used gdb to find it, was fun.
This commit is contained in:
parent
ca287f3dff
commit
58de733df4
3 changed files with 10 additions and 4 deletions
6
Makefile
6
Makefile
|
@ -7,7 +7,7 @@ WARNING_FLAGS := -Wall -Wextra
|
||||||
INCLUDE_FLAGS := -I include
|
INCLUDE_FLAGS := -I include
|
||||||
|
|
||||||
CC := clang
|
CC := clang
|
||||||
CFLAGS := $(WARNING_FLAGS) $(INCLUDE_FLAGS) -DKILO_COMMIT_HASH=$(HASH) -MMD -MP -std=c99 -ggdb
|
CFLAGS := $(WARNING_FLAGS) $(INCLUDE_FLAGS) -DKILO_COMMIT_HASH=$(HASH) -MMD -MP -std=c99 -g
|
||||||
|
|
||||||
kilo: $(OBJS)
|
kilo: $(OBJS)
|
||||||
$(CC) $(CFLAGS) $^ -o $@
|
$(CC) $(CFLAGS) $^ -o $@
|
||||||
|
@ -16,6 +16,10 @@ $(OBJS): build/%.o: src/%.c
|
||||||
@mkdir -p build
|
@mkdir -p build
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
.PHONY: install clean
|
||||||
|
install: kilo
|
||||||
|
cp kilo ~/bin
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build
|
rm -rf build
|
||||||
rm -f ./kilo
|
rm -f ./kilo
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# kilo
|
# kilo
|
||||||
|
|
||||||
My implementation of the [kilo text editor][1], which I wrote by following
|
My implementation of the [kilo text editor][1], which I wrote by following
|
||||||
[this tutorial][2]. The current state is horribly bugged, regrettably so.
|
[this tutorial][2].
|
||||||
|
|
||||||
## How to build
|
## How to build
|
||||||
|
|
||||||
|
|
|
@ -186,14 +186,16 @@ static char *buffer_get_string(struct buffer *buffer, size_t *n_chars) {
|
||||||
|
|
||||||
for (int i = 0; i < buffer->n_rows; i++)
|
for (int i = 0; i < buffer->n_rows; i++)
|
||||||
*n_chars += buffer->rows[i]->n_chars + 1;
|
*n_chars += buffer->rows[i]->n_chars + 1;
|
||||||
|
*n_chars -= 1;
|
||||||
|
|
||||||
char *write_buffer = malloc(*n_chars);
|
char *write_buffer = malloc(*n_chars);
|
||||||
for (int i = 0, j = 0; i < buffer->n_rows; j++, i++) {
|
for (int i = 0, j = 0; i < buffer->n_rows; i++) {
|
||||||
struct erow *row = buffer->rows[i];
|
struct erow *row = buffer->rows[i];
|
||||||
|
|
||||||
memcpy(write_buffer + j, row->chars, row->n_chars);
|
memcpy(write_buffer + j, row->chars, row->n_chars);
|
||||||
j += row->n_chars;
|
j += row->n_chars;
|
||||||
write_buffer[j++] = '\n';
|
if (i < buffer->n_rows - 1)
|
||||||
|
write_buffer[j++] = '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
return write_buffer;
|
return write_buffer;
|
||||||
|
|
Reference in a new issue