首页 > 解决方案 > Getting Unchecked return value from library?

问题描述

Calling remove(file.txt) without checking return value. This library function may fail and return an error code

I am getting above warning in below code-

bool chkfile() {
  std::remove(file.txt);
  return true;
}

How should I remove this warning?

标签: c++static-analysis

解决方案


You can refer to this link to see the issue. You have to check if there is no issue during remove operation.

Your code should be something like this,

bool chkfile() {
  if (std::remove("file.txt") != 0) {
    // error handling
  } else {
    // success
    return true;
  }
}

推荐阅读