[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 09a61c42 2/2: Make (ast-text-prev-in-list): re
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 09a61c42 2/2: Make (ast-text-prev-in-list): return empty when target not in list |
Date: |
Thu, 15 Feb 2024 12:47:25 -0500 (EST) |
branch: master
commit 09a61c429639b989bd168eb54e3c792aba6b4b06
Author: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
Make (ast-text-prev-in-list): return empty when target not in list
Until now, when the desired target to this GNU Make extension was not in
the input list, it would return the last element of the list!
With this commit, it returns NULL in such cases (as documented).
---
lib/makeplugin.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/makeplugin.c b/lib/makeplugin.c
index 157a8013..db7fbb6f 100644
--- a/lib/makeplugin.c
+++ b/lib/makeplugin.c
@@ -209,6 +209,7 @@ static char *
makeplugin_text_prev_in_list(const char *caller, unsigned int argc,
char **argv)
{
+ int found=0;
char *prev=NULL, *target=argv[0];
gal_list_str_t *tmp, *list=gal_list_str_extract(argv[1]);
@@ -216,11 +217,11 @@ makeplugin_text_prev_in_list(const char *caller, unsigned
int argc,
for(tmp=list; tmp!=NULL; tmp=tmp->next)
{
if( strcmp(tmp->v,target) ) prev=tmp->v; /* Not equal. */
- else break; /* Equal. */
+ else {found=1; break;} /* Equal. */
}
/* Return the output. */
- return prev;
+ return found?prev:NULL;
}