diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-07-15 15:36:51 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-07-15 15:36:51 +0100 |
commit | 011d43746faf1bb2a6619e1246143724eb253b52 (patch) | |
tree | 72533d6368e39645e7d104e35e09ac5bcdc0a407 /sway | |
parent | e6209afcd6923d9803c3ea6bacf3f9322a7a7450 (diff) |
Add error handling for getting config file size
Diffstat (limited to 'sway')
-rw-r--r-- | sway/config.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/sway/config.c b/sway/config.c index b8c874e6..2c051146 100644 --- a/sway/config.c +++ b/sway/config.c @@ -561,12 +561,17 @@ static char *expand_line(const char *block, const char *line, bool add_brace) { bool read_config(FILE *file, struct sway_config *config) { bool reading_main_config = false; char *this_config = NULL; - unsigned long config_size = 0; + size_t config_size = 0; if (config->current_config == NULL) { reading_main_config = true; - fseek(file, 0, SEEK_END); - config_size = ftell(file); + int ret_seek = fseek(file, 0, SEEK_END); + long ret_tell = ftell(file); + if (ret_seek == -1 || ret_tell == -1) { + wlr_log(WLR_ERROR, "Unable to get size of config file"); + return false; + } + config_size = ret_tell; rewind(file); config->current_config = this_config = calloc(1, config_size + 1); |