summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/binary-writer.cc4
-rw-r--r--src/common.cc16
2 files changed, 13 insertions, 7 deletions
diff --git a/src/binary-writer.cc b/src/binary-writer.cc
index 2117c8e5..172fc9fc 100644
--- a/src/binary-writer.cc
+++ b/src/binary-writer.cc
@@ -626,8 +626,8 @@ static void write_global_header(Context* ctx, const WabtGlobal* global) {
static void write_reloc_section(Context* ctx, RelocSection* reloc_section) {
char section_name[128];
- sprintf(section_name, "%s.%s", WABT_BINARY_SECTION_RELOC,
- reloc_section->name);
+ wabt_snprintf(section_name, sizeof(section_name), "%s.%s",
+ WABT_BINARY_SECTION_RELOC, reloc_section->name);
begin_custom_section(ctx, section_name, LEB_SECTION_SIZE_GUESS);
wabt_write_u32_leb128(&ctx->stream, reloc_section->section_code,
"reloc section type");
diff --git a/src/common.cc b/src/common.cc
index f2ab97d7..830a17ac 100644
--- a/src/common.cc
+++ b/src/common.cc
@@ -20,10 +20,13 @@
#include <stdio.h>
#include <stdint.h>
#include <string.h>
+#include <limits.h>
#if COMPILER_IS_MSVC
#include <fcntl.h>
#include <io.h>
+#include <stdlib.h>
+#define PATH_MAX _MAX_PATH
#endif
WabtOpcodeInfo g_wabt_opcode_info[WABT_NUM_OPCODES];
@@ -120,29 +123,32 @@ WabtResult wabt_read_file(const char* filename,
size_t* out_size) {
FILE* infile = fopen(filename, "rb");
if (!infile) {
- fprintf(stderr, "unable to read file: %s\n", filename);
+ const char* format = "unable to read file %s";
+ char msg[PATH_MAX + sizeof(format)];
+ wabt_snprintf(msg, sizeof(msg), format, filename);
+ perror(msg);
return WABT_ERROR;
}
if (fseek(infile, 0, SEEK_END) < 0) {
- fprintf(stderr, "fseek to end failed.\n");
+ perror("fseek to end failed");
return WABT_ERROR;
}
long size = ftell(infile);
if (size < 0) {
- fprintf(stderr, "ftell failed.\n");
+ perror("ftell failed");
return WABT_ERROR;
}
if (fseek(infile, 0, SEEK_SET) < 0) {
- fprintf(stderr, "fseek to beginning failed.\n");
+ perror("fseek to beginning failed");
return WABT_ERROR;
}
void* data = wabt_alloc(size);
if (size != 0 && fread(data, size, 1, infile) != 1) {
- fprintf(stderr, "fread failed.\n");
+ perror("fread failed");
return WABT_ERROR;
}