Could happen, should be fixed:
451std::string ArgParse::GetProjectRCFilename() const
452{
453 // Walk up the directory hierarchy from the cwd until we:
454 // 1. Get to the user's $HOME dir, in which case we don't return an rc filename even if it exists.
455 // 2. Find an rc file, which we'll then return the name of.
456 // 3. Can't go up the hierarchy any more (i.e. we hit root).
457 /// @todo We might want to reconsider if we want to start at cwd or rather at whatever
458 /// paths may have been specified on the command line. cwd is what Ack is documented
459 /// to do, and is easier.
460
461 std::string retval;
462
463 // Get a file descriptor to the user's home dir, if there is one.
464 auto homedirname = GetUserHomeDir();
465 int home_fd = -1;
\1. Condition !homedirname.empty(), taking true branch
466 if(!homedirname.empty())
467 {
\2. negative_return_fn: Function open(homedirname.c_str(), 65536) returns a negative number.
\3. var_assign: Assigning: signed variable home_fd = open.
468 home_fd = open(homedirname.c_str(), O_RDONLY | O_DIRECTORY);
469 }
470
471 // Get the current working directory's absolute pathname.
472 /// @note GRVS - get_current_dir_name() under Cygwin will currently return a DOS path if this is started
473 /// under the Eclipse gdb. This mostly doesn't cause problems, except for terminating the loop
474 /// (see below).
475 char _original_cwd = get_current_dir_name();
476
477 //std::clog << "INFO: cwd = "" << original_cwd << """ << std::endl;
478
479 auto current_cwd = original_cwd;
\4. Condition current_cwd != NULL, taking true branch
\5. Condition current_cwd[0] != '.', taking true branch
\13. Condition current_cwd != NULL, taking true branch
\14. Condition current_cwd[0] != '.', taking true branch
480 while((current_cwd != nullptr) && (current_cwd[0] != '.'))
481 {
482 // See if this is the user's $HOME dir.
483 auto cwd_fd = open(current_cwd, O_RDONLY | O_DIRECTORY);
CID 53716: Improper use of negative value (NEGATIVE_RETURNS) [select issue]
\6. Condition is_same_file(cwd_fd, home_fd), taking false branch
CID 53717 (#3-2 of 3): Improper use of negative value (NEGATIVE_RETURNS)15. negative_returns: home_fd is passed to a parameter that cannot be negative. [show details]
484 if(is_same_file(cwd_fd, home_fd))
485 {
486 // We've hit the user's home directory without finding a config file.
487 close(cwd_fd);
488 break;
489 }
490 close(cwd_fd);
491
492 // Try to open the config file.
493 auto test_rc_filename = std::string(current_cwd);
\7. Condition *std::__cxx11::basic_string<char, std::char_traits, std::allocator >::reverse_iterator(test_rc_filename.rbegin()) != '/', taking true branch
494 if(_test_rc_filename.rbegin() != '/')
495 {
496 test_rc_filename += "/";
497 }
498 test_rc_filename += ".ucgrc";
499 //std::clog << "INFO: checking for rc file "" << test_rc_filename << """ << std::endl;
500 auto rc_file = open(test_rc_filename.c_str(), O_RDONLY);
\8. Condition rc_file != -1, taking false branch
501 if(rc_file != -1)
502 {
503 // Found it. Return its name.
504 //std::clog << "INFO: found rc file "" << test_rc_filename << """ << std::endl;
505 retval = test_rc_filename;
506 close(rc_file);
507 break;
508 }
509
510 /// @note GRVS - get_current_dir_name() under Cygwin will currently return a DOS path if this is started
511 /// under the Eclipse gdb. This mostly doesn't cause problems, except for terminating the loop.
512 /// The clause below after the || handles this.
\9. Condition strlen(current_cwd) == 1, taking false branch
\10. Condition strlen(current_cwd) <= 4, taking true branch
\11. Condition current_cwd[1] == ':', taking false branch
513 if((strlen(current_cwd) == 1) || (strlen(current_cwd) <= 4 && current_cwd[1] == ':'))
514 {
515 // We've hit the root and didn't find a config file.
516 break;
517 }
518
519 // Go up one directory.
520 current_cwd = dirname(current_cwd);
\12. Jumping back to the beginning of the loop
521 }
522
523 // Free the cwd string.
524 free(original_cwd);
525
526 // Close the homedir we opened above.
CID 53716: Argument cannot be negative (NEGATIVE_RETURNS) [select issue]
CID 53717 (#1 of 3): Argument cannot be negative (NEGATIVE_RETURNS) [select issue]
527 close(home_fd);
528
529 return retval;
530}