From: Christophe CURIS <christophe.cu...@free.fr>

The "documentation" of the function claims to check for the resource in a
number of path, but factually if the application did provide its argument
list when creating the WINGs App structure (which is likely) then the
search would stop before checking all paths.

The code now continues as expectable if the resource was not found in the
path. Took opportunity to avoid a temporary allocation that participated in
memory fragmentation.

Signed-off-by: Christophe CURIS <christophe.cu...@free.fr>
---
 WINGs/wapplication.c | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/WINGs/wapplication.c b/WINGs/wapplication.c
index 90874c0..39b37d9 100644
--- a/WINGs/wapplication.c
+++ b/WINGs/wapplication.c
@@ -131,11 +131,10 @@ error:
 
 char *WMPathForResourceOfType(const char *resource, const char *ext)
 {
-       char *path, *tmp, *appdir;
-       int i;
+       char *path, *appdir;
        size_t slen;
 
-       path = tmp = appdir = NULL;
+       path = appdir = NULL;
 
        /*
         * Paths are searched in this order:
@@ -156,17 +155,19 @@ char *WMPathForResourceOfType(const char *resource, const 
char *ext)
        }
 
        if (WMApplication.argv[0]) {
-               tmp = wstrdup(WMApplication.argv[0]);
-               i = strlen(tmp);
-               while (i > 0 && tmp[i] != '/')
-                       i--;
-               tmp[i] = 0;
-               if (i > 0) {
+               char *ptr_slash;
+
+               ptr_slash = strrchr(WMApplication.argv[0], '/');
+               if (ptr_slash != NULL) {
+                       char tmp[ptr_slash - WMApplication.argv[0] + 1];
+
+                       strncpy(tmp, WMApplication.argv[0], sizeof(tmp)-1);
+                       tmp[sizeof(tmp) - 1] = '\0';
+
                        path = checkFile(tmp, NULL, ext, resource);
-               } else {
-                       path = NULL;
+                       if (path)
+                               goto out;
                }
-               goto out;
        }
 
        slen = strlen(WMApplication.applicationName) + 
sizeof("Applications/.app");
@@ -197,8 +198,6 @@ char *WMPathForResourceOfType(const char *resource, const 
char *ext)
        path = checkFile("/usr/GNUstep", appdir, ext, resource); /* falls 
through */
 
 out:
-       if (tmp)
-               wfree(tmp);
        if (appdir)
                wfree(appdir);
 
-- 
2.1.1


-- 
To unsubscribe, send mail to wmaker-dev-unsubscr...@lists.windowmaker.org.

Reply via email to