Is anyone bothered by the compiler warnings that indicate that the format strings don't match the associated variables? I was, so I cast most of the objectionable args (pids, uids, gids) to "long", and added an "l" (el) to the format string. A single item was cast to an int. Here's the patch. If you haven't applied my UseLogin patch, the line numbers in session.c will be offset by -16 lines. ..wayne.. ---8<------8<------8<------8<---cut here--->8------>8------>8------>8--- Index: authfile.c @@ -519,7 +519,7 @@ error("@ WARNING: UNPROTECTED PRIVATE KEY FILE! @"); error("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"); error("Bad ownership or mode(0%3.3o) for '%s'.", - st.st_mode & 0777, filename); + (int)(st.st_mode & 0777), filename); error("It is recommended that your private key files are NOT accessible by others."); return 0; } Index: serverloop.c @@ -96,8 +96,8 @@ wait_pid = wait((int *) &child_wait_status); if (wait_pid != -1) { if (wait_pid != child_pid) - error("Strange, got SIGCHLD and wait returned pid %d but child is %d", - wait_pid, child_pid); + error("Strange, got SIGCHLD and wait returned pid %ld but child is %ld", + (long)wait_pid, (long)child_pid); if (WIFEXITED(child_wait_status) || WIFSIGNALED(child_wait_status)) child_terminated = 1; @@ -601,8 +601,8 @@ } else { /* Check if it matches the process we forked. */ if (wait_pid != pid) - error("Strange, wait returned pid %d, expected %d", - wait_pid, pid); + error("Strange, wait returned pid %ld, expected %ld", + (long)wait_pid, (long)pid); } /* We no longer want our SIGCHLD handler to be called. */ Index: session.c @@ -1545,12 +1545,12 @@ int i; for(i = 0; i < MAX_SESSIONS; i++) { Session *s = &sessions[i]; - debug("dump: used %d session %d %p channel %d pid %d", + debug("dump: used %d session %d %p channel %d pid %ld", s->used, s->self, s, s->chanid, - s->pid); + (long)s->pid); } } @@ -1591,13 +1591,13 @@ session_by_pid(pid_t pid) { int i; - debug("session_by_pid: pid %d", pid); + debug("session_by_pid: pid %ld", (long)pid); for(i = 0; i < MAX_SESSIONS; i++) { Session *s = &sessions[i]; if (s->used && s->pid == pid) return s; } - error("session_by_pid: unknown pid %d", pid); + error("session_by_pid: unknown pid %ld", (long)pid); session_dump(); return NULL; } @@ -1905,8 +1905,8 @@ if (c == NULL) fatal("session_close: session %d: no channel %d", s->self, s->chanid); - debug("session_exit_message: session %d channel %d pid %d", - s->self, s->chanid, s->pid); + debug("session_exit_message: session %d channel %d pid %ld", + s->self, s->chanid, (long)s->pid); if (WIFEXITED(status)) { channel_request_start(s->chanid, @@ -1947,7 +1947,7 @@ void session_free(Session *s) { - debug("session_free: session %d pid %d", s->self, s->pid); + debug("session_free: session %d pid %ld", s->self, (long)s->pid); if (s->term) xfree(s->term); if (s->display) @@ -1972,7 +1972,7 @@ { Session *s = session_by_pid(pid); if (s == NULL) { - debug("session_close_by_pid: no session for pid %d", s->pid); + debug("session_close_by_pid: no session for pid %ld", (long)s->pid); return; } if (s->chanid != -1) @@ -1996,15 +1996,15 @@ channel_cancel_cleanup(s->chanid); s->chanid = -1; - debug("session_close_by_channel: channel %d kill %d", id, s->pid); + debug("session_close_by_channel: channel %d kill %ld", id, (long)s->pid); if (s->pid == 0) { /* close session immediately */ session_close(s); } else { /* notify child, delay session cleanup */ if (kill(s->pid, (s->ttyfd == -1) ? SIGTERM : SIGHUP) < 0) - error("session_close_by_channel: kill %d: %s", - s->pid, strerror(errno)); + error("session_close_by_channel: kill %ld: %s", + (long)s->pid, strerror(errno)); } } Index: ssh-agent.c @@ -796,7 +796,7 @@ format = c_flag ? "unsetenv %s;\n" : "unset %s;\n"; printf(format, SSH_AUTHSOCKET_ENV_NAME); printf(format, SSH_AGENTPID_ENV_NAME); - printf("echo Agent pid %d killed;\n", pid); + printf("echo Agent pid %ld killed;\n", (long)pid); exit(0); } parent_pid = getpid(); @@ -849,7 +849,7 @@ SSH_AUTHSOCKET_ENV_NAME); printf(format, SSH_AGENTPID_ENV_NAME, pidstrbuf, SSH_AGENTPID_ENV_NAME); - printf("echo Agent pid %d;\n", pid); + printf("echo Agent pid %ld;\n", (long)pid); exit(0); } if (setenv(SSH_AUTHSOCKET_ENV_NAME, socket_name, 1) == -1 || Index: sshconnect.c @@ -748,7 +748,7 @@ /* Get local user name. Use it as server user if no user name was given. */ pw = getpwuid(original_real_uid); if (!pw) - fatal("User id %u not found from user database.", original_real_uid); + fatal("User id %lu not found from user database.", (long)original_real_uid); local_user = xstrdup(pw->pw_name); server_user = options.user ? options.user : local_user; Index: sshd.c @@ -1053,7 +1053,7 @@ if (pid < 0) error("fork: %.100s", strerror(errno)); else - debug("Forked child %d.", pid); + debug("Forked child %ld.", (long)pid); close(startup_p[1]); Index: sshpty.c @@ -318,12 +318,12 @@ if (st.st_uid != pw->pw_uid || st.st_gid != gid) { if (chown(ttyname, pw->pw_uid, gid) < 0) { if (errno == EROFS && st.st_uid == pw->pw_uid) - error("chown(%.100s, %d, %d) failed: %.100s", - ttyname, pw->pw_uid, gid, + error("chown(%.100s, %ld, %ld) failed: %.100s", + ttyname, (long)pw->pw_uid, (long)gid, strerror(errno)); else - fatal("chown(%.100s, %d, %d) failed: %.100s", - ttyname, pw->pw_uid, gid, + fatal("chown(%.100s, %ld, %ld) failed: %.100s", + ttyname, (long)pw->pw_uid, (long)gid, strerror(errno)); } } @@ -332,11 +332,11 @@ if (chmod(ttyname, mode) < 0) { if (errno == EROFS && (st.st_mode & (S_IRGRP | S_IROTH)) == 0) - error("chmod(%.100s, 0%o) failed: %.100s", - ttyname, mode, strerror(errno)); + error("chmod(%.100s, 0%lo) failed: %.100s", + ttyname, (long)mode, strerror(errno)); else - fatal("chmod(%.100s, 0%o) failed: %.100s", - ttyname, mode, strerror(errno)); + fatal("chmod(%.100s, 0%lo) failed: %.100s", + ttyname, (long)mode, strerror(errno)); } } } ---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
mouring at etoh.eviladmin.org
2001-Apr-04 18:05 UTC
compiler warnings about format strings
On Wed, 4 Apr 2001, Wayne Davison wrote:> Is anyone bothered by the compiler warnings that indicate that the > format strings don't match the associated variables? I was, so I cast > most of the objectionable args (pids, uids, gids) to "long", and added > an "l" (el) to the format string. A single item was cast to an int. > > Here's the patch. If you haven't applied my UseLogin patch, the line > numbers in session.c will be offset by -16 lines. >What platform is this for? Majority of the platforms I'm on pid is defined as u_int/int not u_long/long so I don't personally see such mismatch errors. - Ben