From b5932d1d22d35cef95eb1cffbf489619b264442d Mon Sep 17 00:00:00 2001 From: Chris Xiong Date: Fri, 6 Jul 2018 21:25:39 +0800 Subject: Random code clean-ups to get ready for the next update. Also tweaked the config a little bit. --- utils.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'utils.cpp') diff --git a/utils.cpp b/utils.cpp index a661794..135dd0a 100644 --- a/utils.cpp +++ b/utils.cpp @@ -23,15 +23,17 @@ float readfloat(const char* path) fclose(f); return atof(buf); } -std::string readstr(const char* path) +std::string readstr(const char* path,int max_length) { FILE* f=fopen(path,"r"); if(!f)return LOG('W',"failed to open %s for reading: %d",path,errno),""; - char buf[256]; - ignore_result(fgets(buf,256,f)); - buf[255]=0; + char* buf=new char[max_length+1]; + ignore_result(fgets(buf,max_length+1,f)); + buf[max_length]=0; fclose(f); - return std::string(buf); + std::string ret(buf); + delete buf; + return ret; } void writeint(const char* path,int v) { -- cgit v1.2.3