Python-2.7.3/Parser/firstsets.c

Location Tool Test ID Function Issue
/builddir/build/BUILD/Python-2.7.3/Parser/firstsets.c:66:12 clang-analyzer Array access (from variable 'sym') results in a null pointer dereference
/builddir/build/BUILD/Python-2.7.3/Parser/firstsets.c:66:12 clang-analyzer Array access (from variable 'sym') results in a null pointer dereference
/builddir/build/BUILD/Python-2.7.3/Parser/firstsets.c:81:26 clang-analyzer Array access (from variable 'sym') results in a null pointer dereference
/builddir/build/BUILD/Python-2.7.3/Parser/firstsets.c:81:26 clang-analyzer Array access (from variable 'sym') results in a null pointer dereference
  1 /* Computation of FIRST stets */
  2 
  3 #include "pgenheaders.h"
  4 #include "grammar.h"
  5 #include "token.h"
  6 
  7 extern int Py_DebugFlag;
  8 
  9 /* Forward */
 10 static void calcfirstset(grammar *, dfa *);
 11 
 12 void
 13 addfirstsets(grammar *g)
 14 {
 15     int i;
 16     dfa *d;
 17 
 18     if (Py_DebugFlag)
 19         printf("Adding FIRST sets ...\n");
 20     for (i = 0; i < g->g_ndfas; i++) {
 21         d = &g->g_dfa[i];
 22         if (d->d_first == NULL)
 23             calcfirstset(g, d);
 24     }
 25 }
 26 
 27 static void
 28 calcfirstset(grammar *g, dfa *d)
 29 {
 30     int i, j;
 31     state *s;
 32     arc *a;
 33     int nsyms;
 34     int *sym;
 35     int nbits;
 36     static bitset dummy;
 37     bitset result;
 38     int type;
 39     dfa *d1;
 40     label *l0;
 41 
 42     if (Py_DebugFlag)
 43         printf("Calculate FIRST set for '%s'\n", d->d_name);
 44 
 45     if (dummy == NULL)
 46         dummy = newbitset(1);
 47     if (d->d_first == dummy) {
 48         fprintf(stderr, "Left-recursion for '%s'\n", d->d_name);
 49         return;
 50     }
 51     if (d->d_first != NULL) {
 52         fprintf(stderr, "Re-calculating FIRST set for '%s' ???\n",
 53             d->d_name);
 54     }
 55     d->d_first = dummy;
 56 
 57     l0 = g->g_ll.ll_label;
 58     nbits = g->g_ll.ll_nlabels;
 59     result = newbitset(nbits);
 60 
 61     sym = (int *)PyObject_MALLOC(sizeof(int));
 62     if (sym == NULL)
 63         Py_FatalError("no mem for new sym in calcfirstset");
 64     nsyms = 1;
 65     sym[0] = findlabel(&g->g_ll, d->d_type, (char *)NULL);
 66 
Array access (from variable 'sym') results in a null pointer dereference
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

Array access (from variable 'sym') results in a null pointer dereference
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

67 s = &d->d_state[d->d_initial]; 68 for (i = 0; i < s->s_narcs; i++) { 69 a = &s->s_arc[i]; 70 for (j = 0; j < nsyms; j++) { 71 if (sym[j] == a->a_lbl) 72 break; 73 } 74 if (j >= nsyms) { /* New label */ 75 sym = (int *)PyObject_REALLOC(sym, 76 sizeof(int) * (nsyms + 1)); 77 if (sym == NULL) 78 Py_FatalError( 79 "no mem to resize sym in calcfirstset"); 80 sym[nsyms++] = a->a_lbl; 81 type = l0[a->a_lbl].lb_type;
Array access (from variable 'sym') results in a null pointer dereference
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

Array access (from variable 'sym') results in a null pointer dereference
(emitted by clang-analyzer)

TODO: a detailed trace is available in the data model (not yet rendered in this report)

82 if (ISNONTERMINAL(type)) { 83 d1 = PyGrammar_FindDFA(g, type); 84 if (d1->d_first == dummy) { 85 fprintf(stderr, 86 "Left-recursion below '%s'\n", 87 d->d_name); 88 } 89 else { 90 if (d1->d_first == NULL) 91 calcfirstset(g, d1); 92 mergebitset(result, 93 d1->d_first, nbits); 94 } 95 } 96 else if (ISTERMINAL(type)) { 97 addbit(result, a->a_lbl); 98 } 99 } 100 } 101 d->d_first = result; 102 if (Py_DebugFlag) { 103 printf("FIRST set for '%s': {", d->d_name); 104 for (i = 0; i < nbits; i++) { 105 if (testbit(result, i)) 106 printf(" %s", PyGrammar_LabelRepr(&l0[i])); 107 } 108 printf(" }\n"); 109 } 110 111 PyObject_FREE(sym); 112 }