Ziehier een simpele functie in mijn IRC botje die ik probeer te schrijven:
Hier is mijn output:
Met andere woorden, ik raak de variabelen username en hostname kwijt (die worden weer NULL) tussen regel 45 en regel 54, terwijl ik er niets mee doe! De output bewijst dat voor regel 45 deze variabelen wel bestaan. Hoe kan dat?
.
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
| IrcUser * irc_user_new_from_mask (IrcConnection *irc_connection, gchar *hostmask) { IrcUser *irc_user; gchar *nickname = NULL, *hostname = NULL, *username = NULL; gint i = 0; g_return_val_if_fail(hostmask != NULL, NULL); /* parse the hostmask */ g_print("Mask: %s\n", hostmask); while (1) { if (hostmask[i] == '!' || hostmask[i] == '\0') { nickname = g_strndup(hostmask, i); if (hostmask[i] == '!') i++; if (hostmask[i] == '~') i++; hostmask = &hostmask[i]; g_print("Nickname found: %s\n", nickname); break; } else i++; } i = 0; g_print("Mask: %s\n", hostmask); while (1) { if (hostmask[i] == '@' || hostmask[i] == '\0') { if (i != 0) { username = g_strndup(hostmask, i); if (hostmask[i] == '@') i++; hostmask = &hostmask[i]; g_print("Username found: %s\n", username); } break; } else i++; } i = 0; g_print("Mask: %s\n", hostmask); if (hostmask[i] != '\0') hostname = g_strdup(hostmask); g_print("Hostname: %s\n", hostname); irc_user = irc_user_new_from_nick(irc_connection, nickname); if (irc_user->username) g_free(irc_user->username); irc_user->username = username; if (irc_user->hostname) g_free(irc_user->hostname); irc_user->hostname = hostname; g_print("Nick: %s, user: %s, host: %s\n", nickname, username, hostname); return irc_user; } |
Hier is mijn output:
code:
1
2
3
4
5
6
7
| Mask: BBB!rbultje@csop.nixhelp.org Nickname found: BBB Mask: rbultje@csop.nixhelp.org Username found: rbultje Mask: csop.nixhelp.org Hostname: csop.nixhelp.org Name: BBB, User: (null), Host: (null) |
Met andere woorden, ik raak de variabelen username en hostname kwijt (die worden weer NULL) tussen regel 45 en regel 54, terwijl ik er niets mee doe! De output bewijst dat voor regel 45 deze variabelen wel bestaan. Hoe kan dat?