tizen 2.3.1 release
[framework/uifw/embryo.git] / src / lib / embryo_str.c
index cd3b942..95163ce 100644 (file)
@@ -2,28 +2,41 @@
 # include "config.h"
 #endif
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <fnmatch.h>
-
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
 #ifdef HAVE_ALLOCA_H
 # include <alloca.h>
-#elif defined __GNUC__
-# define alloca __builtin_alloca
-#elif defined _AIX
-# define alloca __alloca
-#elif defined _MSC_VER
-# include <malloc.h>
-# define alloca _alloca
-#else
-# include <stddef.h>
-# ifdef  __cplusplus
+#elif !defined alloca
+# ifdef __GNUC__
+#  define alloca __builtin_alloca
+# elif defined _AIX
+#  define alloca __alloca
+# elif defined _MSC_VER
+#  include <malloc.h>
+#  define alloca _alloca
+# elif !defined HAVE_ALLOCA
+#  ifdef  __cplusplus
 extern "C"
-# endif
+#  endif
 void *alloca (size_t);
+# endif
+#endif
+
+#ifdef HAVE_EXOTIC
+# include <Exotic.h>
 #endif
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fnmatch.h>
+
 #include "Embryo.h"
 #include "embryo_private.h"
 
@@ -276,7 +289,7 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params)
    /* params[2] = bufsize */
    /* params[3] = format_string */
    /* params[4] = first arg ... */
-   if (params[0] < (3 * sizeof(Embryo_Cell))) return 0;
+   if (params[0] < (Embryo_Cell)(3 * sizeof(Embryo_Cell))) return 0;
    if (params[2] <= 0) return 0;
    STRGET(ep, s1, params[3]);
    if (!s1) return -1;
@@ -386,15 +399,18 @@ _embryo_str_snprintf(Embryo_Program *ep, Embryo_Cell *params)
                            int l;
 
                            STRGET(ep, tmp, params[4 + p]);
-                           l = strlen(tmp);
-                           if ((o + l) > (params[2] - 1))
-                             {
-                                l = params[2] - 1 - o;
-                                if (l < 0) l = 0;
-                                tmp[l] = 0;
-                             }
-                           strcpy(s2 + o, tmp);
-                           o += l;
+             if (tmp)
+               {
+                  l = strlen(tmp);
+                  if ((o + l) > (params[2] - 1))
+                    {
+                       l = params[2] - 1 - o;
+                       if (l < 0) l = 0;
+                       tmp[l] = 0;
+                    }
+                  strcpy(s2 + o, tmp);
+                  o += l;
+               }
                            p++;
                         }
                       break;
@@ -439,6 +455,7 @@ _embryo_str_strchr(Embryo_Program *ep, Embryo_Cell *params)
    if (params[0] != (2 * sizeof(Embryo_Cell))) return 0;
    STRGET(ep, s1, params[1]);
    STRGET(ep, s2, params[2]);
+   if ((!s1) || (!s2)) return -1;
    p = strchr(s1, s2[0]);
    if (!p) return -1;
    return (Embryo_Cell)(p - s1);
@@ -454,6 +471,7 @@ _embryo_str_strrchr(Embryo_Program *ep, Embryo_Cell *params)
    if (params[0] != (2 * sizeof(Embryo_Cell))) return 0;
    STRGET(ep, s1, params[1]);
    STRGET(ep, s2, params[2]);
+   if ((!s1) || (!s2)) return -1;
    p = strrchr(s1, s2[0]);
    if (!p) return -1;
    return (Embryo_Cell)(p - s1);