From 354844f79fae4d4bf2d2c4f057d3a79e7fa11572 Mon Sep 17 00:00:00 2001 From: Aethor Date: Fri, 2 Jun 2017 13:43:31 +0200 Subject: [PATCH] =?UTF-8?q?recursive=20globbing,=20mais=20=C3=A7a=20leak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fish_shell/fish_globbing.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fish_shell/fish_globbing.c b/fish_shell/fish_globbing.c index 808f0ee..e326a50 100644 --- a/fish_shell/fish_globbing.c +++ b/fish_shell/fish_globbing.c @@ -79,9 +79,8 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ int i = 0; int indexToExpand = -1; - //TODO : free WordList* pathToList = splitWordIntoList(path, '/'); - WordListElement* tempElement; //beware of the size, should be checked before anyway + WordListElement* tempElement; //beware of the size, should be checked before anyway (?) tempElement = pathToList->first; @@ -104,13 +103,14 @@ void recursiveExpandWord(char* path, WordList* listToExpand){ } else{ - char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand); + char* correctedPath = concatWordListToWord(pathToList,0, indexToExpand + 1); WordList* foundFiles = getFiles(getPath(correctedPath), getFileName(correctedPath)); + printWordList(foundFiles); if(foundFiles->size > 0){ tempElement = foundFiles->first; - char* concatenedEndOfPath = concatWordListToWord(foundFiles, indexToExpand + 1, foundFiles->size - 1); + char* concatenedEndOfPath = concatWordListToWord(pathToList, indexToExpand + 1, foundFiles->size - 1); for(i=0; i < foundFiles->size; i++){ @@ -141,6 +141,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) int i; char* concatenedString = (char*) malloc(sizeof(char)); if(concatenedString == NULL) crash(); + concatenedString[0] = '\0'; if(lastElemIndex > list->size -1){ lastElemIndex = list->size - 1; @@ -159,7 +160,7 @@ char* concatWordListToWord(WordList* list,int firstElemIndex, int lastElemIndex) } for(i=firstElemIndex; i < lastElemIndex; i++){ - trueStrcat(concatenedString, tempElement->word); + concatenedString = trueStrcat(concatenedString, tempElement->word); tempElement = tempElement->next; } @@ -314,6 +315,11 @@ WordList* splitWordIntoList(char* string, char splitChar){ WordList* newWordList = createWordList(); if(newWordList == NULL) crash(); + if(string[0] == '.'){ + addEndWordList(newWordList, (char*) "."); + i++; + } + while(!finished){ if(string[i] == splitChar || string[i] == '\0'){