[Prev][Next][Index]

alpha: sageroot improperly handled (fix enclosed0




The following code is from pC++2dep/pc++.c:

    /* determine SAGEROOT */
    if (fopen(SAGEROOT, "r") != NULL) {
      strcat(SageRoot, SAGEROOT);
      }
    else if ((in = fopen("./SAGEROOT", "r")) != NULL) {
      fgets(SageRoot, 1024, in);
      fclose(in);
      SageRoot[strlen(SageRoot)-1] = '\0'; /*chop off newline*/
      }
    else if ((p = getenv("SAGEROOT")) != NULL) {
      strcat(SageRoot, p);
      }
    else {
      fprintf(stderr,"ERROR: cannot find SAGEROOT\n");
      return 1;
      }

Unfortunately, SageRoot is not initialized to the empty string, and
so the strcat in cases 1 and 3 is wrong; it should be strcpy.

The error manifests itself on the alpha either because the compiler
initializes the string (my current theory; it is always '.init') or
because that architecture has incredibly stable garbage in memory :-)

--lars