jdg@antique.UUCP (John Gabbe) (02/24/89)
James McClelland accepted this fix for later versions of the PDP program. For those of you who have earlier versions the following may be helpful. April 20, 1988 PDP Software Inquiries c/o Texts Manager MIT Press 55 Hayward Street Cambridge, MA 02142 Dear Sir: The PDP software file ../src/weights.c, contains errors in the segments reproduced below. The pertinent lines are marked with an E# or C in the left margin, which serves as a key to the comments that follow the code. * * * * * * * * * * * * * * * * * * * * /* This file is part of the PDP software package. Copyright 1987 by James L. McClelland and David E. Rumelhart. Please refer to licensing information in the file license.txt, which is in the same directory with this source file and is included here by reference. */ /* file: weights.c read in network descriptions, and set up constraints. First version implemented by Elliot Jaffe. Date of last revision: 8-12-87/JLM. */ line 21 . . . line 609 if (nlinks) { constraints = (struct constraint *) emalloc ((unsigned int)(sizeof (struct constraint) * (nlinks + 1))); for (i = 0; i < nlinks; i++) { constraints[i].num = 0; constraints[i].max = MAXCONSTRAINTS; constraints[i].cvec = ((float **) emalloc((unsigned int)(sizeof(float *) * MAXCONSTRAINTS))); constraints[i].ivec = ((float **) emalloc((unsigned int)(sizeof(float *) * MAXCONSTRAINTS))); E1 for (j = 0; j < nunits; j++) { constraints[i].cvec[j] = NULL; constraints[i].ivec[j] = NULL; } } } line 626 . . . line 783 /* realloc positive_constraints, negative_constraints, and link constraints this is called whenever the allocated constraint lists run out of space for additional constraints 14-May-87 MAF / 15-May-87 JLM */ enlarge_constraints(con_index) int con_index; { E2 if (con_index = ENLARGE_POS) { C maxpos += 100; positive_constraints = ((float **) erealloc ((char *) positive_constraints, C (unsigned int) ((maxpos - 100) * sizeof(float *)), (unsigned int) (maxpos * sizeof(float *)))); } E3 else if (con_index = ENLARGE_NEG) { C maxneg += 100; negative_constraints = ((float **) erealloc ((char *) negative_constraints, C (unsigned int) ((maxneg -100) * sizeof (float *)), (unsigned int) (maxneg * sizeof(float *)))); } else { C constraints[con_index].max += 100; constraints[con_index].cvec = ((float **) erealloc ((char *)constraints[con_index].cvec, (unsigned int) C ((constraints[con_index].max - 100) * sizeof(float *)), (unsigned int) (constraints[con_index].max * sizeof(float *)))); constraints[con_index].ivec = ((float **) erealloc ((char *)constraints[con_index].ivec, (unsigned int) C ((constraints[con_index].max - 100) * sizeof(float *)), (unsigned int) (constraints[con_index].max * sizeof(float *)))); E4 } } * * * * * * * * * * * * * * * * * * * * E1. At the line marked E1, MAXCONSTRAINTS items have just been emalloc'd but nunits items are NULL'ed. When nunits > MAXCONSTRAINTS, unallocated memory is overwritten destroying (on Suns and Vaxen) malloc's bookkeeping and leading to a segmentation error. This line should be replaced by: for (j = 0; j < nunits && j < MAXCONSTRAINTS; j++) { E2, E3. These should be compares, not assignments. Replace `=' with `=='. As the code is written, positive_constraints is always erealloc'd and nothing else is ever erealloc'd. E4. If it is necessary to NULL the pointers at E1, then it should be necessary to NULL the additional space allocated here. C. For consistency, all the 100's should be replaced by MAXCONSTRAINTS. The following code inserted at E4 will then initialize the additional space: for (j = constraints[con_index].max - MAXCONSTRAINTS; j < constraints[con_index].max; j++) { constraints[con_index].cvec[j] = NULL; constraints[con_index].ivec[j] = NULL; } These comments are provided as a courtesy; no claims are made or responsibility assumed regarding their correctness. Yours truly, John D. Gabbe AT&T Bell Laboratories copy to netnews comp.ai.neural-nets P.S. In the official revision, McClellen introduced an additional constant to implement comment C, instead of overloading MAXCONSTRAINTS as is done above. - JDG 2/24/89.