More warning suppressions
[sxemacs] / src / editfns.c
index abb35e3..a32f51b 100644 (file)
@@ -600,11 +600,10 @@ On Unix it is obtained from TMPDIR, with /tmp as the default.
 {
        char *tmpdir;
        tmpdir = getenv("TMPDIR");
+       char path[5 /* strlen ("/tmp/") */  + 1 + _POSIX_PATH_MAX];
        if (!tmpdir) {
                struct stat st;
                int myuid = getuid();
-               char path[5 /* strlen ("/tmp/") */  + 1 +
-                          _POSIX_PATH_MAX];
 
                strcpy(path, "/tmp/");
                strncat(path, user_login_name(NULL), _POSIX_PATH_MAX);
@@ -616,29 +615,32 @@ On Unix it is obtained from TMPDIR, with /tmp as the default.
                    S_ISDIR(st.st_mode)) {
                        tmpdir = path;
                } else {
-                        strncpy(path, getenv("HOME"), sizeof(path)-1);
-                       strncat(path, "/tmp/", sizeof(path)-strlen(path)-1);
-                       if (stat(path, &st) < 0 && errno == ENOENT) {
-                               int fd;
-                               char warnpath[ 
-                                              /* strlen(".created_by_sxemacs") */ 
-                                              19 + _POSIX_PATH_MAX + 1];
-                               mkdir(path, 0700);      /* ignore retvals */
-                               strncpy(warnpath, path, _POSIX_PATH_MAX);
-                                warnpath[sizeof(warnpath)-1]=0;
-
-                                /* we already are reserved these 20 bytes... */
-                               strcat(warnpath, ".created_by_sxemacs");
-                               if ((fd =
-                                    open(warnpath, O_WRONLY | O_CREAT,
-                                         0644)) > 0) {
-                                       write(fd,
-                                             "SXEmacs created this directory because /tmp/<yourname> was unavailable -- \nPlease check !\n",
-                                             89);
-                                       close(fd);
+                       const char* home_env = getenv("HOME");
+                       if ( home_env ) {
+                               strncpy(path, home_env, sizeof(path)-1);
+                               strncat(path, "/tmp/", sizeof(path)-1);
+                               if (stat(path, &st) < 0 && errno == ENOENT) {
+                                       int fd;
+                                       char warnpath[ 
+                                               /* strlen(".created_by_sxemacs") */ 
+                                               19 + _POSIX_PATH_MAX + 1];
+                                       mkdir(path, 0700);      /* ignore retvals */
+                                       strncpy(warnpath, path, _POSIX_PATH_MAX);
+                                       warnpath[sizeof(warnpath)-1]=0;
+                                       
+                                       /* we already are reserved these 20 bytes... */
+                                       strcat(warnpath, ".created_by_sxemacs");
+                                       if ((fd = open(warnpath, O_WRONLY | O_CREAT,
+                                                      0644)) > 0) {
+                                               write(fd, "SXEmacs created this directory "
+                                                         "because /tmp/<yourname> "
+                                                         "was unavailable -- \nPlease check !\n",  89);
+                                               close(fd);
+                                       }
                                }
                        }
-                       if (stat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
+                       if (stat(path, &st) == 0 && st.st_uid == (uid_t) myuid 
+                           && S_ISDIR(st.st_mode)) {
                                tmpdir = path;
                        } else {
                                tmpdir = "/tmp";
@@ -1347,9 +1349,10 @@ If you want them to stand for years in this century, you must do that yourself.
                        tzstring = (char *)XSTRING_DATA(zone);
                } else if (INTP(zone)) {
                        int abszone = abs(XINT(zone));
-                       snprintf(tzbuf, countof(tzbuf) - 1, "XXX%s%d:%02d:%02d",
-                                "-" + (XINT(zone) < 0), abszone / (60 * 60),
-                                (abszone / 60) % 60, abszone % 60);
+                       int sz = snprintf(tzbuf, sizeof(tzbuf), "XXX%s%d:%02d:%02d",
+                                         "-" + (XINT(zone) < 0), abszone / (60 * 60),
+                                         (abszone / 60) % 60, abszone % 60);
+                       assert(sz >= 0 && (size_t)sz < sizeof(tzbuf));
                        tzstring = tzbuf;
                } else {
                        error("Invalid time zone specification");
@@ -1421,9 +1424,10 @@ Like `encode-time' but return a big integer time instead.
                        tzstring = (char *)XSTRING_DATA(zone);
                else if (INTP(zone)) {
                        int abszone = abs(XINT(zone));
-                       sprintf(tzbuf, "XXX%s%d:%02d:%02d",
-                               "-" + (XINT(zone) < 0), abszone / (60 * 60),
-                               (abszone / 60) % 60, abszone % 60);
+                       int sz = snprintf(tzbuf, sizeof(tzbuf), "XXX%s%d:%02d:%02d",
+                                         "-" + (XINT(zone) < 0), abszone / (60 * 60),
+                                         (abszone / 60) % 60, abszone % 60);
+                       assert(sz>=0 && (size_t)sz < sizeof(tzbuf));
                        tzstring = tzbuf;
                } else
                        error("Invalid time zone specification");
@@ -1559,8 +1563,10 @@ the data it can't find.
                        /* No local time zone name is available; use "+-NNNN"
                           instead.  */
                        int am = (offset < 0 ? -offset : offset) / 60;
-                       sprintf(buf, "%c%02d%02d", (offset < 0 ? '-' : '+'),
-                               am / 60, am % 60);
+                       int sz = snprintf(buf, sizeof(buf), "%c%02d%02d", 
+                                         (offset < 0 ? '-' : '+'),
+                                         am / 60, am % 60);
+                       assert(sz>=0 && (size_t)sz < sizeof(buf));
                        s = buf;
                }
                return list2(make_int(offset), build_string(s));