From dfa8d40a759b5a65874aa32d47a7d1908ccabd80 Mon Sep 17 00:00:00 2001 From: Lakshya Singh Date: Thu, 6 May 2021 19:32:18 +0530 Subject: [PATCH] refactor : throw complete error instead of short change precomp script to check with full name justify selection of 16 in parser.cpp add and rename variables to precomp for better clarity Signed-off-by: Lakshya Singh --- compiler/parser/parser.cpp | 20 +++++++++++-------- .../errors/nameLength/longName.precomp | 10 +++++----- 2 files changed, 17 insertions(+), 13 deletions(-) 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