From fc4835f81ddc61d26306b4e6101a7ff3f448fbd8 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 16 Feb 2016 21:58:05 +0100 Subject: [PATCH] Cosmetics while hunting a bug of memory misbehavior --- src/surf/storage_interface.cpp | 21 ++++++++------------- src/surf/surfxml_parse.cpp | 4 ++-- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/surf/storage_interface.cpp b/src/surf/storage_interface.cpp index 1761cf6e48..026ed9a18c 100644 --- a/src/surf/storage_interface.cpp +++ b/src/surf/storage_interface.cpp @@ -103,12 +103,9 @@ xbt_dict_t Storage::parseContent(const char *filename) return NULL; xbt_dict_t parse_content = xbt_dict_new_homogeneous(xbt_free_f); - FILE *file = NULL; - file = surf_fopen(filename, "r"); - if (file == NULL) - xbt_die("Cannot open file '%s' (path=%s)", filename, - xbt_str_join(surf_path, ":")); + FILE *file = surf_fopen(filename, "r"); + xbt_assert(file, "Cannot open file '%s' (path=%s)", filename, xbt_str_join(surf_path, ":")); char *line = NULL; size_t len = 0; @@ -118,14 +115,12 @@ xbt_dict_t Storage::parseContent(const char *filename) while ((read = xbt_getline(&line, &len, file)) != -1) { if (read){ - if(sscanf(line,"%s %llu", path, &size) == 2) { - m_usedSize += size; - sg_size_t *psize = xbt_new(sg_size_t, 1); - *psize = size; - xbt_dict_set(parse_content,path,psize,NULL); - } else { - xbt_die("Be sure of passing a good format for content file.\n"); - } + xbt_assert(sscanf(line,"%s %llu", path, &size) == 2, "Parse error in %s: %s",filename,line); + + m_usedSize += size; + sg_size_t *psize = xbt_new(sg_size_t, 1); + *psize = size; + xbt_dict_set(parse_content,path,psize,NULL); } } free(line); diff --git a/src/surf/surfxml_parse.cpp b/src/surf/surfxml_parse.cpp index 7bb17c0256..a0c9a43487 100644 --- a/src/surf/surfxml_parse.cpp +++ b/src/surf/surfxml_parse.cpp @@ -314,8 +314,8 @@ void STag_surfxml_include(void) xbt_dynar_push(surf_file_to_parse_stack, &surf_file_to_parse); //save old file descriptor surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor - xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", - A_surfxml_include_file); + xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file); + xbt_dynar_push(surf_input_buffer_stack,&surf_input_buffer); surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE); surf_parse_push_buffer_state(surf_input_buffer); -- 2.20.1