Я получаю следующую ошибку при использовании strncpy:
Invalid read of size 1
==11703== at 0x4C2D791: __strncpy_sse2_unaligned (vg_replace_strmem.c:555)
==11703== by 0x400BD6: searchGNode
Это функция searchGNode. Я читал другие сообщения stackoverflow, в которых говорится, что null завершает строки, в которых вы используете strncpy, однако я все еще получаю сообщение об ошибке. Я пробовал делать это и раньше, и после использования strncpy, и, похоже, это не работает. В чем может быть проблема?
41 GNode * searchGNode ( GNode * root, GNode * newnode, int * flag,int k,GNode * last)
42 {
43 GNode * found = NULL;
44 char rootstr[MAX_KMER_LEN];
45 char newstr[MAX_KMER_LEN];
46 if (root == NULL)
47 {
48 return found;
49 }
50 //rootstr[k] = '\0';
51 //newstr[k] = '\0';
52 strncpy(rootstr,root->key,k); // copy the root's key into here
53 strncpy(newstr,newnode->key,k); // copy the newnode's key iinto here
54 /*if (root == NULL)
55 {
56 return found; // returning null
57 }*/
58 rootstr[k] = '\0';
59 newstr[k] = '\0';
60 if ( strcmp(rootstr,newstr) == 0)
61 {
62 return root; // this is the match , we have found that this node exists in the graph
63 }
64 found = searchGNode(root->one,newnode,flag,k,last); // search first pointer
65 if (found != NULL)
66 {
67 *flag = 1;
68 insertGNode(last,found); // insert if we find
69 return found;
70 }
71 found = searchGNode(root->two,newnode,flag,k,last);
72 if (found != NULL)
73 {
74 *flag = 1;
75 insertGNode(last,found);
76 return found;
77 }
78 found = searchGNode(root->three,newnode,flag,k,last);
79 if (found != NULL)
80 {
81 *flag = 1;
82 insertGNode(last,found);
83 return found;
84 }
85 found = searchGNode(root->four,newnode,flag,k,last);
86 if (found != NULL)
87 {
88 *flag = 1;
89 insertGNode(last,found);
90 return found;
91 }
92 return newnode;
93 }
Я тоже пробовал strcpy и получаю ту же ошибку.