Good day, everybody!

In debug mode I encounter massive stack corruption, with the help of global 
call_stack array. The only reason to this is plain return in function or no 
EDBUG() macro at the start of the function. 
        So i suggest to join DBGCHECK from events.c and EDBUG macro, here is the 
patch:

--- ./etalon/e16/e/src/E.h      2004-08-31 21:24:39.000000000 +0400
+++ ./hacked/e16/e/src/E.h      2004-09-07 11:52:40.959028008 +0400
@@ -128,44 +128,72 @@
 /* and being able to trace E for profiling/optimisation purposes (which */
 /* believe it or not I'm actually doing) */
 
-/* #define DEBUG 1 */
+/*#define DEBUG 1 
 
 #ifdef DEBUG
-extern int          call_level;
-extern char        *call_stack[1024];
-
+extern int          call_level                   ;
+extern char        *call_stack[1024]             ;
+extern int          save_stack                   ;
 #endif
+
 #ifdef DEBUG
-#define EDBUG(l,x) \
-{ \
-  call_stack[call_level] = x; \
-  call_level++; \
-}
+  #define EDBUG(l,x)\
+  {\
+    save_stack = call_level + 1                  ;\
+    fprintf(stderr,"Entered %s with call level %i\n",x,call_level);\
+    call_stack[call_level] = x                   ;\
+    call_level++                                 ;\
+  }
 #else
-#define EDBUG(l,x)  \
-;
+  #define EDBUG(l,x)\
+  ;
 #endif
 
-#ifdef DEBUG
-#define EDBUG_RETURN(x)  \
-{ \
-  call_level--; \
-  return (x); \
-}
-#define EDBUG_RETURN_  \
-{ \
-  call_level--; \
-  return; \
-}
+#ifdef DEBUG  
+  #define EDBUG_RETURN(x)\
+  {\
+      if (save_stack != call_level)\
+      {\
+          fprintf (stderr, "Unstack error with saved value %i : 
[",save_stack);\
+          for (save_stack = 0; save_stack < call_level; save_stack++)\
+          {\
+              fprintf (stderr, "%s%s", save_stack ? ", " : "", 
call_stack[save_stack]);\
+          }\
+          fprintf (stderr, "]\n")               ;\
+          fprintf (stderr, "file %s , line %i\n",__FILE__,__LINE__);\
+          save_stack = call_level               ;\
+      }\
+      call_level--                              ;\
+      fprintf(stderr,"Exited %s with call level 
%i\n",call_stack[call_level],call_level);\
+      return (x)                                ;\
+  }
+   
+  #define EDBUG_RETURN_\
+  {\
+      if (save_stack != call_level)\
+      {\
+          fprintf (stderr, "Unstack error with saved value %i : 
[",save_stack);\
+          for (save_stack = 0; save_stack < call_level; save_stack++)\
+          {\
+              fprintf (stderr, "%s%s", save_stack ? ", " : "", 
call_stack[save_stack]);\
+          }\
+          fprintf (stderr, "]\n")               ;\
+          fprintf (stderr, "file %s , line %i\n",__FILE__,__LINE__);\
+          save_stack = call_level               ;\
+      }\
+      call_level--                              ;\
+      fprintf(stderr,"Exited %s with call level 
%i\n",call_stack[call_level],call_level);\
+      return                                    ;\
+  }
 #else
-#define EDBUG_RETURN(x)  \
-{ \
-  return (x); \
-}
-#define EDBUG_RETURN_  \
-{ \
-  return; \
-}
+  #define EDBUG_RETURN(x)\
+  {\
+    return (x)                                   ;\
+  }
+  #define EDBUG_RETURN_\
+  {\
+    return                                       ;\
+  }
 #endif
 
 #ifdef HAVE_SNPRINTF

Another issue is the lack of brackets around this macro in the code, there are 
blocks in macro, but still the code should work under any circumstances, here 
is the patch, also i add some commentary (i believe, if everybody each time 
when he/she submit something, add commentary to an arbitrary function, very 
soon we get very well documented code :-)):

--- file-e.c    2004-07-13 03:33:15.000000000 +0400
+++ file.c      2004-09-07 12:05:18.838812768 +0400
@@ -101,21 +101,46 @@
      }
 }
 
+/**
+ * Check whether file with a name s is a regular file.
+ *
+ * Parameters :
+ *   s    - pointer to a null terminated file name.
+ *
+ * Return value :
+ *   0    - if a given name corresponds to a non regular file.
+ *   1    - if a given name corresponds to a regular file.
+ */
 int
 isfile(const char *s)
-{
-   struct stat         st;
-
-   EDBUG(9, "isfile");
-   if ((!s) || (!*s))
-      EDBUG_RETURN(0);
-   if (stat(s, &st) < 0)
-      EDBUG_RETURN(0);
-   if (S_ISREG(st.st_mode))
-      EDBUG_RETURN(1);
-   EDBUG_RETURN(0);
+{       
+    struct stat         st                      ;
+  
+    EDBUG(9, "isfile")                          ;
+    
+    /*if name is NULL or '\0'                   */
+    if ((!s) || (!*s))
+    {      
+        EDBUG_RETURN(0)                         ;   
+    }
+    
+    if (stat(s, &st) < 0)
+    {          
+        if (DEBUG)
+        {
+            perror("isfile")                    ;   
+        }
+        EDBUG_RETURN(0)                         ;
+    }
+    
+    if (S_ISREG(st.st_mode))
+    {      
+        EDBUG_RETURN(1)                         ;
+    }   
+    EDBUG_RETURN(0)                             ;
 }
 
+
 int
 isdir(const char *s)
 {
@@ -123,11 +148,17 @@
 
    EDBUG(9, "isdir");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN(0);
+   }
    if (stat(s, &st) < 0)
+   {
       EDBUG_RETURN(0);
+   }
    if (S_ISDIR(st.st_mode))
+   {
       EDBUG_RETURN(1);
+   }
    EDBUG_RETURN(0);
 }
 
@@ -148,7 +179,9 @@
 
    EDBUG(9, "ls");
    if ((!dir) || (!*dir))
+   {
       EDBUG_RETURN(0);
+   }
    dirp = opendir(dir);
    if (!dirp)
      {
@@ -166,7 +199,9 @@
    names = (char **)Emalloc(dirlen * sizeof(char *));
 
    if (!names)
+   {
       EDBUG_RETURN(NULL);
+   }
 
    rewinddir(dirp);
    for (i = 0; i < dirlen;)
@@ -210,7 +245,9 @@
 {
    EDBUG(9, "freestrlist");
    if (!l)
+   {
       EDBUG_RETURN_;
+   }
    while (num--)
       if (l[num])
         Efree(l[num]);
@@ -223,7 +260,9 @@
 {
    EDBUG(9, "rm");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN_;
+   }
    unlink(s);
    EDBUG_RETURN_;
 }
@@ -233,7 +272,9 @@
 {
    EDBUG(9, "mv");
    if ((!s) || (!ss) || (!*s) || (!*ss))
+   {
       EDBUG_RETURN_;
+   }
    rename(s, ss);
    EDBUG_RETURN_;
 }
@@ -247,13 +288,19 @@
 
    EDBUG(9, "cp");
    if ((!s) || (!ss) || (!*s) || (!*ss))
+   {
       EDBUG_RETURN_;
+   }
    if (!exists(s))
+   {
       EDBUG_RETURN_;
+   }
    i = filesize(s);
    f = fopen(s, "r");
    if (!f)
+   {
       EDBUG_RETURN_;
+   }
    ff = fopen(ss, "w");
    if (!ff)
      {
@@ -274,11 +321,17 @@
 
    EDBUG(9, "moddate");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN(0);
+   }
    if (stat(s, &st) < 0)
+   {
       EDBUG_RETURN(0);
+   }
    if (st.st_mtime > st.st_ctime)
+   {
       EDBUG_RETURN(st.st_mtime);
+   }
    EDBUG_RETURN(st.st_ctime);
 }
 
@@ -289,9 +342,13 @@
 
    EDBUG(9, "filesize");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN(0);
+   }
    if (stat(s, &st) < 0)
+   {
       EDBUG_RETURN(0);
+   }
    EDBUG_RETURN((int)st.st_size);
 }
 
@@ -302,9 +359,13 @@
 
    EDBUG(9, "filesize");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN(0);
+   }
    if (stat(s, &st) < 0)
+   {
       EDBUG_RETURN(0);
+   }
    EDBUG_RETURN((int)st.st_ino);
 }
 
@@ -315,9 +376,13 @@
 
    EDBUG(9, "filesize");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN(0);
+   }
    if (stat(s, &st) < 0)
+   {
       EDBUG_RETURN(0);
+   }
    EDBUG_RETURN((int)st.st_dev);
 }
 
@@ -326,7 +391,9 @@
 {
    EDBUG(9, "cd");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN_;
+   }
    chdir(s);
    EDBUG_RETURN_;
 }
@@ -350,9 +417,13 @@
 
    EDBUG(9, "permissions");
    if ((!s) || (!*s))
+   {
       EDBUG_RETURN(0);
+   }
    if (stat(s, &st) < 0)
+   {
       EDBUG_RETURN(0);
+   }
    EDBUG_RETURN(st.st_mode);
 }
 
@@ -394,15 +465,21 @@
 
    EDBUG(9, "username");
    if (usr_uid < 0)
+   {
       usr_uid = getuid();
+   }
    if ((uid == usr_uid) && (usr_s))
+   {
       EDBUG_RETURN(Estrdup(usr_s));
+   }
    pwd = getpwuid(uid);
    if (pwd)
      {
        s = Estrdup(pwd->pw_name);
        if (uid == usr_uid)
+       {
           usr_s = Estrdup(s);
+       }
        EDBUG_RETURN(s);
      }
    EDBUG_RETURN(Estrdup("unknown"));
@@ -418,7 +495,9 @@
 
    EDBUG(9, "homedir");
    if (usr_uid < 0)
+   {
       usr_uid = getuid();
+   }
    if ((uid == usr_uid) && (usr_s))
      {
        EDBUG_RETURN(Estrdup(usr_s));
@@ -428,7 +507,9 @@
      {
        s = Estrdup(pwd->pw_dir);
        if (uid == usr_uid)
+       {
           usr_s = Estrdup(s);
+       }
        EDBUG_RETURN(s);
      }
    EDBUG_RETURN(Estrdup((getenv("TMPDIR") == NULL) ?
@@ -445,21 +526,33 @@
 
    EDBUG(9, "usershell");
    if (usr_uid < 0)
+   {
       usr_uid = getuid();
+   }
    if ((uid == usr_uid) && (usr_s))
-      return Estrdup(usr_s);
+   {
+      EDBUG_RETURN(usr_s)                        ;
+   }
    pwd = getpwuid(uid);
    if (pwd)
      {
        if (!pwd->pw_shell)
+       {
           EDBUG_RETURN(Estrdup("/bin/sh"));
+       }
        if (strlen(pwd->pw_shell) < 1)
+       {
           EDBUG_RETURN(Estrdup("/bin/sh"));
+       }
        if (!(canexec(pwd->pw_shell)))
+       {
           EDBUG_RETURN(Estrdup("/bin/sh"));
+       }
        s = Estrdup(pwd->pw_shell);
        if (uid == usr_uid)
+       {
           usr_s = Estrdup(s);
+       }
        EDBUG_RETURN(s);
      }
    EDBUG_RETURN(Estrdup("/bin/sh"));
@@ -472,7 +565,9 @@
 
    EDBUG(9, "atword");
    if (!s)
+   {
       EDBUG_RETURN(NULL);
+   }
    cnt = 0;
    i = 0;
 
@@ -485,7 +580,9 @@
             else if ((s[i - 1] == ' ') || (s[i - 1] == '\t'))
                cnt++;
             if (cnt == num)
+            {
                EDBUG_RETURN(&s[i]);
+            }
          }
        i++;
      }
@@ -499,12 +596,16 @@
 
    EDBUG(9, "atchar");
    if (!s)
+   {
       EDBUG_RETURN(NULL);
+   }
    i = 0;
    while (s[i] != 0)
      {
        if (s[i] == c)
+       {
           EDBUG_RETURN(&s[i]);
+       }
        i++;
      }
    EDBUG_RETURN(NULL);
 



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click
_______________________________________________
enlightenment-devel mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to