diff --git a/compiler/parser/parser.cpp b/compiler/parser/parser.cpp index 3d9665b42fb4..755571e44228 100644 --- a/compiler/parser/parser.cpp +++ b/compiler/parser/parser.cpp @@ -331,19 +331,23 @@ static void parseCommandLineFiles() { if (isChplSource(inputFileName)) { /* - Ensure that all the files parsed don't exceed the - (NAME_MAX - 16) i.e. 239 bytes Limits + Selection of 16 is did so as to provide + enough space for generating files like .tmp.obj + whose length is 8 so selection of double the required */ - const size_t maxFileName = NAME_MAX - 16; + const size_t reductionMaxLength = 16; + /* + Ensure that all the files parsed don't exceed + (NAME_MAX - reductionMaxLength) e.g. 239 bytes on + unix and linux system. + */ + const size_t maxFileName = NAME_MAX - reductionMaxLength; if (strlen(inputFileName) > maxFileName) { - char reducedFileName[maxFileName]; - // sprintf fileName to allowed length buffer - strncpy(reducedFileName, inputFileName, maxFileName); - // error message to print between filename and filename limit + // error message to print placeholders for fileName and maxLength const char *errorMessage = "%s, filename is longer than maximum allowed length of %d\n"; // throwr error will concatenated messages - USR_FATAL(errorMessage, reducedFileName, maxFileName); + USR_FATAL(errorMessage, inputFileName, maxFileName); } parseFile(inputFileName, MOD_USER, true, false); } diff --git a/test/parsing/errors/nameLength/longName.precomp b/test/parsing/errors/nameLength/longName.precomp index 829e9d41eabb..6d7da1e83902 100755 --- a/test/parsing/errors/nameLength/longName.precomp +++ b/test/parsing/errors/nameLength/longName.precomp @@ -1,8 +1,9 @@ #!/usr/bin/env bash NAME_MAX=`getconf NAME_MAX /` -NAME_MAX=$((NAME_MAX - 15)) -LIMIT=$((NAME_MAX - 1)) +REDUCTIONMAXLENGTH=16 +LIMIT=$((NAME_MAX - REDUCTIONMAXLENGTH)) +OUTOFBOUND=$((LIMIT + 1)) VAL="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" repeatChar() { @@ -12,10 +13,9 @@ repeatChar() { printf '%s\n' "${myString// /$input}" } -FILENAME=$(repeatChar a $NAME_MAX) +FILENAME=$(repeatChar a $OUTOFBOUND) printf 'module LongName {\n\tfunc printSomething() {\n\t\twrite(%s); \n\t}\n}' "'Won't Compile'" > $VAL/$FILENAME.chpl touch $VAL/$FILENAME.notest printf 'require %s;' "'$FILENAME.chpl'" > $VAL/longNameHelper.chpl touch $VAL/longNameHelper.notest -FILENAME=$(repeatChar a $LIMIT) -printf "error: %s, filename is longer than maximum allowed length of %d\n\n" $FILENAME $LIMIT > $VAL/longName.good +printf "error: %s, filename is longer than maximum allowed length of %d\n\n" $FILENAME.chpl $LIMIT > $VAL/longName.good