Pablo Galindo Salgado <[email protected]> added the comment:
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
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41215>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com