Я новичок в C, работаю через 'Crack' на pset2 CS50. Я пытаюсь сравнить argv [1] со строкой ha sh, которая является выводом функции crypt C.
Код выдает следующую ошибку:
runtime error: null pointer passed as argument 1, which is declared to never be null
/usr/include/string.h:137:33: note: nonnull attribute specified here
Я мог бы использовать некоторую помощь, чтобы понять, что означает эта ошибка и как она вызвана, поэтому я могу найти способ обойти ее. Я искал похожие проблемы, но не смог понять точную причину. Код выполняется без ошибок, пока не появится последний оператор if.
#include <stdio.h>
#include <crypt.h>
#include <math.h>
#include <cs50.h>
#include <string.h>
int main(int argc, string argv[])
{
if (argc != 2)
{
printf("Usage: ./crack hash"); // Error message for incorrect usage
return 1;
}
else
{
char slt_str[3], slt1[1], slt2[1], pwd[5];
string hash;
for (int i = '.'; i <= 'z'; i++) //first character of salt
{
for (int j = '.'; j <= 'z'; j++) //second character of salt permuted against first
{
slt1[0] = i, slt2[0] = j; //arrays to hold first and second character of salt respectively
slt_str[0] = slt1[0]; // 1st char of salt array is first char of first partial salt array
slt_str[1] = slt2[0]; // 2nd char of salt array is 1st char of 2nd partial salt array
slt_str[2] = '\0'; // 3rd character of salt array is null zero
//printf("\n%s",crypt("abc", slt_str));
// salt + permutation code to go here //
for (int k = 'A'; k <= 'z'; k++)
{
pwd[0] = k;
pwd[1] = '\0';
//printf("%s\n", crypt(pwd, slt_str));
hash = crypt(pwd, slt_str);
//printf("%s", crypt(pwd, slt_str));
if (strcmp(argv[2], hash) == 0)
{
printf("%c", pwd[0]);
}
}
}
}
}
}