Skip to content

Commit

Permalink
refactor : throw complete error instead of short
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
king-11 committed May 9, 2021
1 parent ac81a75 commit dfa8d40
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
20 changes: 12 additions & 8 deletions compiler/parser/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions test/parsing/errors/nameLength/longName.precomp
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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

0 comments on commit dfa8d40

Please sign in to comment.