1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Patch for Devin Steffler.

Fixed Bug 100947 	[BaseScanner] empty string for 91086 fix can create a bad key for the CodeReaderCache
This commit is contained in:
John Camelon 2005-06-24 17:55:37 +00:00
parent 46044323e3
commit 14c4a4fb50
3 changed files with 27 additions and 18 deletions

View file

@ -2839,6 +2839,23 @@ abstract class BaseScanner implements IScanner {
}
CodeReader reader = null;
// filename is an absolute path or it is a Linux absolute path on a windows machine
if (new File(filename).isAbsolute() || filename.startsWith("/")) { //$NON-NLS-1$
reader = createReader( EMPTY_STRING, filename );
if (reader != null) {
pushContext(reader.buffer, new InclusionData(reader,
createInclusionConstruct(fileNameArray,
reader.filename, local, startOffset,
startingLine, nameOffset,
nameEndOffset, nameLine, endOffset,
endLine, false)));
return;
}
handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, startOffset,
fileNameArray);
return;
}
File currentDirectory = null;
if (local || include_next) {
// if the include is eclosed in quotes OR we are in an include_next
@ -2893,23 +2910,6 @@ abstract class BaseScanner implements IScanner {
}
}
}
// if not found by this point, and the inclusion is local, try just the
// path as is (bug 91086)
if( local && !include_next )
{
reader = createReader( EMPTY_STRING, filename );
if (reader != null) {
pushContext(reader.buffer, new InclusionData(reader,
createInclusionConstruct(fileNameArray,
reader.filename, local, startOffset,
startingLine, nameOffset,
nameEndOffset, nameLine, endOffset,
endLine, false)));
return;
}
}
handleProblem(IProblem.PREPROCESSOR_INCLUSION_NOT_FOUND, startOffset,
fileNameArray);
}

View file

@ -84,7 +84,9 @@ public class ScannerUtility {
if( ! path.equals( "" )) //$NON-NLS-1$
{
newPathBuffer.append( new File(path).getPath() );
newPathBuffer.append( File.separatorChar );
if (fileName.length() > 0 && fileName.toCharArray()[0] != File.separatorChar)
newPathBuffer.append( File.separatorChar );
}
newPathBuffer.append( fileName );
//remove ".." and "." segments

View file

@ -9,6 +9,8 @@
package org.eclipse.cdt.core.parser;
import java.io.File;
import org.eclipse.cdt.internal.core.parser.ast.EmptyIterator;
import org.eclipse.cdt.internal.core.util.ILRUCacheable;
import org.eclipse.cdt.internal.core.util.LRUCache;
@ -137,6 +139,11 @@ public class CodeReaderCache implements ICodeReaderCache {
// not in the cache
if (ret == null) {
// for efficiency: check File.exists before ParserUtil#createReader()
// bug 100947 fix: don't want to attempt to create a code reader if there is no file for the key
if (!(new File(key).exists()))
return null;
ret = ParserUtil.createReader(key, EmptyIterator.EMPTY_ITERATOR);
if (cache.getSpaceLimit() > 0)