From 0095976d215d8670f9dfeacd921eb71981a5aa8c Mon Sep 17 00:00:00 2001 From: csoler Date: Sat, 5 Jun 2010 19:05:18 +0000 Subject: [PATCH] added verification for file size computation (bug correction) git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5.0@3068 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/p3cfgmgr.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libretroshare/src/pqi/p3cfgmgr.cc b/libretroshare/src/pqi/p3cfgmgr.cc index 8f5a004ea..54fc9fd9a 100644 --- a/libretroshare/src/pqi/p3cfgmgr.cc +++ b/libretroshare/src/pqi/p3cfgmgr.cc @@ -724,12 +724,22 @@ bool p3Config::backedUpFileSave(const std::string& cfg_fname, const std::string& cfg_file = fopen(cfg_fname.c_str(), "wb"); if(cfg_file == NULL) + { std::cerr << "p3Config::backedUpFileSave() fopen failed for file:" << cfg_fname << std::endl; + return false ; + } } //determine file size fseek(cfg_file, 0L, SEEK_END); size_file = ftell(cfg_file); + + if(size_file < 0) // ftell returns -1 when fails + { + fclose(cfg_file); + size_file = 0 ; + } + fseek(cfg_file, 0L, SEEK_SET); #ifdef CONFIG_DEBUG