Message373112
This is enough to reproduce the problem:
#include <stdio.h>
typedef struct {
char *str;
int type;
} KeywordToken;
static KeywordToken *the_array[] = {
NULL,
NULL,
(KeywordToken[]) {
{"if", 510},
{"in", 518},
{"as", 520},
{"is", 527},
{"or", 532},
{NULL, -1},
},
NULL,
NULL,
(KeywordToken[]) {
{"del11", 503},
{"try22", 511},
{NULL, -1},
},
NULL
};
int main() {
for (int s=0; s<7;s++) {
KeywordToken *tok = the_array[s];
printf("--> %i\n",s);
if (tok == NULL) {
continue;
}
printf("--> %i %.*s\n", s,s, tok->str);
}
return 0;
}
[cpython (3.9)]$ xlc check_bad.c -o check_bad
[cpython (3.9)]$ ./check_bad
--> 0
--> 1
--> 2
Segmentation fault (core dumped)
But if you change it to:
#include <stdio.h>
typedef struct {
char *str;
int type;
} KeywordToken;
static KeywordToken *the_array[] = {
(KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) {
{"if", 510},
{"in", 518},
{"as", 520},
{"is", 527},
{"or", 532},
{NULL, -1},
},
(KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) {{NULL, -1}},
(KeywordToken[]) {
{"del11", 503},
{"try22", 511},
{NULL, -1},
},
(KeywordToken[]) {{NULL, -1}},
};
int main() {
for (int s=0; s<7;s++) {
KeywordToken *tok = the_array[s];
if (tok == NULL) {
continue;
}
printf("--> %i %.*s\n", s,s, tok->str);
}
return 0;
}
[cpython (3.9)]$ xlc check.c -o check
[cpython (3.9)]$ ./check
--> 0
--> 1
--> 2 if
--> 3
--> 4
--> 5 del11
--> 6 |
|
Date |
User |
Action |
Args |
2020-07-06 12:37:21 | pablogsal | set | recipients:
+ pablogsal, skrah, David.Edelsohn, Michael.Felt, lys.nikolaou |
2020-07-06 12:37:20 | pablogsal | set | messageid: <1594039040.95.0.662013019583.issue41215@roundup.psfhosted.org> |
2020-07-06 12:37:20 | pablogsal | link | issue41215 messages |
2020-07-06 12:37:20 | pablogsal | create | |
|