Skip to content

Commit 5fbdaa7

Browse files
committed
lib: handle stream extraction failure with fail() check
ensure read failure is detected if file is empty or contains invalid data. Closes #179. Signed-off-by: Siddhesh Dharme <siddheshdharme18@gmail.com>
1 parent 49045c0 commit 5fbdaa7

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/lib.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ int read_sysfs(const string &filename, bool *ok)
199199
try
200200
{
201201
file >> i;
202+
if(file.fail()){
203+
if(ok)
204+
*ok = false;
205+
return 0;
206+
}
202207
if (ok)
203208
*ok = true;
204209
} catch (std::exception &exc) {

0 commit comments

Comments
 (0)