瀏覽代碼

Fixing misc "errors" from newest version of gcc

Vinicius Teshima 1 年之前
父節點
當前提交
bdf046ca4c
共有 5 個文件被更改,包括 15 次插入12 次删除
  1. 5 4
      src/app.h
  2. 5 4
      src/buffer.h
  3. 2 1
      src/config.h
  4. 1 1
      src/file.h
  5. 2 2
      src/shader.h

+ 5 - 4
src/app.h

@@ -42,7 +42,7 @@ struct app {
 	uint64_t target_fps;
 	double dt;
 	uint32_t last_press;
-	SDL_KeyCode last_pressed_key;
+	SDL_Keycode last_pressed_key;
 	struct {
 		uint8_t tab_size;
 	} cfg;
@@ -289,7 +289,8 @@ app_create_buffer_list(struct app *app)
 static SDL_KeyCode
 char_to_keycode(char c)
 {
-	return char_to_lower(c);
+	char c_ = char_to_lower(c);
+	return (SDL_KeyCode) c_;
 }
 
 static SDL_KeyCode
@@ -337,7 +338,7 @@ char_to_keymod(char c)
 	case 'S': return KMOD_SHIFT; break;
 	case 'A': return KMOD_ALT; break;
 	case 'M': return KMOD_GUI; break;
-	default: return -1; break;
+	default: return (SDL_Keymod) -1; break;
 	}
 }
 
@@ -419,7 +420,7 @@ app_add_global_keybind(struct app *app, const char *keybind,
 			.func = func,
 			.dir = dir
 		};
-		HT_ISET(app->kbds, (int64_t)(key + mod), kbd);
+		HT_ISET(app->kbds, (int64_t)(key) + (int64_t)(mod), kbd);
 	}
 
 	DA_DESTROY(words);

+ 5 - 4
src/buffer.h

@@ -384,15 +384,16 @@ buffer_insert_str_as_line(struct buffer *buf, struct str str)
 void
 buffer_insert_char(struct buffer *buf, char c, size_t index)
 {
-	if ( index > buf->data.size ) {
+	if ( index >= buf->data.size ) {
 		DA_APPEND(buf->data, c);
-		++buf->cur;
-		return;
+		goto exit;
 	}
 
+
 	DA_INSERT(buf->data, c, index);
-	++buf->cur;
 
+exit: ;
+	++buf->cur;
 	buffer_run_hooks(buf, &buf->hooks.insert);
 }
 

+ 2 - 1
src/config.h

@@ -39,11 +39,12 @@ void config(struct app *app) {
 
 	AAGK(app, "C-x b", keybind_list_buffers, DIR_NO);
 
-	char *k = calloc(sizeof(char), 2);
+	char *k = calloc(2, sizeof(char));
 	for ( char c = 32; c < 127; ++c) {
 		k[0] = c;
 		AAGK(app, k, keybind_insert_last_pressed_key, DIR_NO);
 	}
+	free(k);
 }
 
 #undef AAGK

+ 1 - 1
src/file.h

@@ -59,7 +59,7 @@ file_read_all(const char *filepath, size_t *size, enum file_err *err)
 	}
 
 	const size_t buf_size = ((size_t)file_size) + 1;
-	uint8_t *buf = calloc(sizeof(uint8_t), buf_size);
+	uint8_t *buf = calloc(buf_size, sizeof(uint8_t));
 	if ( buf == NULL ) {
 		file_err_set(err, FILE_ERR_FAIL_CALLOC);
 		close(fd);

+ 2 - 2
src/shader.h

@@ -55,7 +55,7 @@ shader_compile_source(const char *src, GLenum type)
 		int32_t log_length = 1024;
 		glGetShaderiv(shdr, GL_INFO_LOG_LENGTH, &log_length);
 		log_length += 10;
-		char *log = calloc(sizeof(char), (size_t)log_length);
+		char *log = calloc((size_t)log_length, sizeof(char));
 		glGetShaderInfoLog(shdr, log_length, NULL, log);
 		fprintf(stderr, "FAILED COMPILE %s : %s\n",
 			shader_type_to_cstr(type), log);
@@ -144,7 +144,7 @@ program_link(uint32_t vert_shader, uint32_t frag_shader)
 		int32_t log_length = 1024;
 		glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &log_length);
 		log_length += 10;
-		char *log = calloc(sizeof(char), (size_t)log_length);
+		char *log = calloc((size_t)log_length, sizeof(char));
 		glGetProgramInfoLog(prog, log_length, NULL, log);
 		fprintf(stderr, "FAILED LINK PROG: %s\n", log);
 		goto err;