Ignore:
Timestamp:
Aug 28, 2012, 5:34:09 PM (13 years ago)
Author:
Frederik Heber <heber@…>
Children:
2d0bba
Parents:
4dfef04
Message:

FIX: Fixing bad_alloc in setOutputBaseName().

  • setOutputBaseName() checks for prefix of filename (stuff before dot). If no dot is present, the size of the char buffer depends on the address of the basename_source. This lead to sporadic bad_allocs.
  • Now, we create the temporary basename in MPQCJob::Work() with a ".in" suffix.
  • Moreover, setOutputBaseName() checks whether a dot is present and if not just takes the length of the given filename.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/bin/mpqc/mpqc.cc

    r4dfef04 r499cea  
    451451  if (output) basename_source = output;
    452452  else        basename_source = input;
    453   int nfilebase = (int) (::strrchr(basename_source, '.') - basename_source);
     453  const char *baseprefix = ::strrchr(basename_source, '.');
     454  int nfilebase = 1;
     455  if (baseprefix == NULL) {
     456    std::cerr << "setOutputBaseName() - ERROR: basename_source "
     457        << basename_source << " contains no dot (.)." << std::endl;
     458    nfilebase = ::strlen(basename_source);
     459  } else
     460    nfilebase = (int) (baseprefix - basename_source);
    454461  char *basename = new char[nfilebase + 1];
    455462  strncpy(basename, basename_source, nfilebase);
     
    18441851  std::ifstream test;
    18451852  do {
    1846     char filename_template[] = "mpqc_temp_XXXXXX";
     1853    char filename_template[] = "mpqc_temp_XXXXXX.in";
    18471854    output = mktemp(filename_template);
    18481855    test.open(output);
     
    18931900  const char *generic_input = 0;
    18941901  getInputFileNames(object_input, generic_input, options, optind, argc, argv);
    1895   const char *input;
     1902  const char *input = 0;
    18961903  if (object_input) input = object_input;
    18971904  if (generic_input) input = generic_input;
Note: See TracChangeset for help on using the changeset viewer.