wjwwood / serial

Cross-platform, Serial Port library written in C++
http://wjwwood.github.com/serial/
MIT License
2.13k stars 1.04k forks source link

gcc compiler warning: variable ‘glob_retval’ set but not used [-Wunused-but-set-variable] #193

Open LeMoussel opened 5 years ago

LeMoussel commented 5 years ago

What steps will reproduce the problem?

  1. Compile serial using gcc gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
  2. Observe warning messages.

What is the expected output? No warnings

What do you see instead?

warning: variable ‘glob_retval’ set but not used [-Wunused-but-set-variable] int glob_retval = glob(patterns[0].c_str(), 0, NULL, &glob_results);

Trivially fixed by removing glob_retval variable :

vector<string>
glob(const vector<string>& patterns)
{
    vector<string> paths_found;

    if(patterns.size() == 0)
        return paths_found;

    glob_t glob_results;

    glob(patterns[0].c_str(), 0, NULL, &glob_results);

    vector<string>::const_iterator iter = patterns.begin();

    while(++iter != patterns.end())
    {
        glob(iter->c_str(), GLOB_APPEND, NULL, &glob_results);
    }

    for(unsigned int path_index = 0; path_index < glob_results.gl_pathc; path_index++)
    {
        paths_found.push_back(glob_results.gl_pathv[path_index]);
    }

    globfree(&glob_results);

    return paths_found;
}