[PATCH] Fix invalid memory access in llvm-mc if file ends in non-newline whitespace or comma

Rafael Ávila de Espíndola rafael.espindola at gmail.com
Thu Nov 6 14:04:28 PST 2014


I find the code a bit hard to read as written.

can we rewrite it to be just a series of "if (not interesting) { eat; continue to see if there is more;}"? Something like

static bool SkipToToken(StringRef &Str) {
  for (;;) {
    if (Str.empty())
      return false;

    // Strip horizontal whitespace and commas.                                   
    if (size_t Pos = Str.find_first_not_of(" \t\r,")) {
      Str = Str.substr(Pos);
      continue;
    }

    if (Str[0] == '#') {
      Str = Str.substr(Str.find_first_of('\n'));
      continue;
    }

    if (Str[0] == '\n') {
      Str = Str.substr(1);
      continue;
    }

    return true;
  }
}

http://reviews.llvm.org/D6151






More information about the llvm-commits mailing list