Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 718833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:34:21+00:00 2026-05-14T05:34:21+00:00

For some reason, I’m having a hard time trying to cover the block of

  • 0

For some reason, I’m having a hard time trying to cover the block of code below. This code is an excerpt from the UNIX uniq command. I’m trying to write test cases to cover all blocks, but can’t seem to reach this block:

if (nfiles == 2)
{
    // Generic error routine
}

In context:

int main (int argc, char **argv)
{
    int optc = 0;
    bool posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL);
    int nfiles = 0;
    char const *file[2];

    file[0] = file[1] = "-";
    program_name = argv[0];

    skip_chars = 0;
    skip_fields = 0;
    check_chars = SIZE_MAX;

    for (;;)
    {
        /* Parse an operand with leading "+" as a file after "--" was
        seen; or if pedantic and a file was seen; or if not
        obsolete.  */

        if (optc == -1 || (posixly_correct && nfiles != 0) || ((optc = getopt_long (argc, argv, "-0123456789Dcdf:is:uw:", longopts, NULL)) == -1))
        {
            if (optind == argc)
                break;
            if (nfiles == 2)
            {
                // Handle errors
            }
            file[nfiles++] = argv[optind++];
        }
        else switch (optc)
        {
            case 1:
            {
                unsigned long int size;
                if (optarg[0] == '+' && posix2_version () < 200112 && xstrtoul (optarg, NULL, 10, &size, "") == LONGINT_OK && size <= SIZE_MAX)
                    skip_chars = size;
                else if (nfiles == 2)
                {
                    // Handle error
                }
                else
                    file[nfiles++] = optarg;
            }
            break;
        }
    }
}

Any help would be greatly appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:34:21+00:00Added an answer on May 14, 2026 at 5:34 am

    It appears this could be reached when more than 2 files are supplied on the command line. In that case, nfiles would reach the value 2 after the name of the second file has been stored in file[1]. When the code checking nfiles == 2 is reached a third time, then the value will already be 2, and the error handling will execute.

    There are two if statements in question. That in switch case “1” can only be reached by using the option in longopts with val == 1.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

for some reason after having changed my code from this: <script type=text/javascript> $(document).ready(function(){ $(recipebutton1).click(function(){
For some reason, after submitting a string like this Jack’s Spindle from a text
For some reason that I don't understand, when I create my SurfaceView from an
For some reason, this works in all major browsers, but not IE (surprise, surprise).
for some reason this image, which is a jpg isn't showing up in IE7
For some reason I never see this done. Is there a reason why not?
For some reason if I try to display data with the following code, I
For some reason, I can not get this dialog to show up on the
For some reason, exceptions thrown in an __autoload function aren't being caught when trying
For some reason, I need to restart a GLSurfaceView.Renderer so I want some time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.