0

I had written this function for argument checking but it is showing this type of error

vigenere.c:26:20: runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/string.h:400:33: note: nonnull attribute specified here
Segmentation fault

my code

int check (char arg[])
{
    int j = 0;
    int k = strlen(arg);
    for (int i = 0; i < k; i++)
    {
        if(isdigit(arg[i]))
        {
            j = 1;
        }
    }
return j;
}

1 Answer 1

2

You forgot to include the relevant code.

You probably call your check function with a NULL pointer. This might happen for example if you use argv[1] before checking whether argc is greater than 1 (or here: equals 2), otherwise that array element wouldn't exist, and could have any value.

6
  • What is args ? Did you mean argc?
    – Rahul
    Mar 1, 2017 at 13:55
  • agin I tried this one but it is not working
    – Rahul
    Mar 1, 2017 at 14:03
  • int check (char arg[]) { int j = 0; int k = strlen(arg); if (arg != NULL) { for (int i = 0; i < k; i++) { if(isdigit(arg[i])) { j = 1; } } } return j; }
    – Rahul
    Mar 1, 2017 at 14:04
  • Yes, I meant argc, sorry. Problem is not your check function, but the code calling it with a NULL pointer, and check crashes on strlen, so your check on NULL won't be reached.
    – Blauelf
    Mar 1, 2017 at 14:37
  • So what should I do?
    – Rahul
    Mar 3, 2017 at 6:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .