=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/top/commands.c,v retrieving revision 1.6 retrieving revision 1.7 diff -c -r1.6 -r1.7 *** src/usr.bin/top/commands.c 2002/07/15 17:20:36 1.6 --- src/usr.bin/top/commands.c 2003/04/06 20:39:20 1.7 *************** *** 1,4 **** ! /* $OpenBSD: commands.c,v 1.6 2002/07/15 17:20:36 deraadt Exp $ */ /* * Top users/processes display for Unix --- 1,4 ---- ! /* $OpenBSD: commands.c,v 1.7 2003/04/06 20:39:20 tdeval Exp $ */ /* * Top users/processes display for Unix *************** *** 56,63 **** static char *next_field(char *); static int scanint(char *, int *); static char *err_string(void); ! static int str_adderr(char *, int, int); ! static int str_addarg(char *, int, char *, int); static int err_compar(const void *, const void *); /* --- 56,63 ---- static char *next_field(char *); static int scanint(char *, int *); static char *err_string(void); ! static size_t str_adderr(char *, size_t, int); ! static size_t str_addarg(char *, size_t, char *, int); static int err_compar(const void *, const void *); /* *************** *** 215,221 **** int cnt = 0; int first = Yes; int currerr = -1; - int stringlen; /* characters still available in "string" */ static char string[STRMAX]; /* if there are no errors, return NULL */ --- 215,220 ---- *************** *** 230,236 **** /* need a space at the front of the error string */ string[0] = ' '; string[1] = '\0'; - stringlen = STRMAX - 2; /* loop thru the sorted list, building an error string */ while (cnt < errcnt) --- 229,234 ---- *************** *** 240,246 **** { if (currerr != -1) { ! if ((stringlen = str_adderr(string, stringlen, currerr)) < 2) { return(err_listem); } --- 238,245 ---- { if (currerr != -1) { ! if (str_adderr(string, sizeof string, currerr) > ! (sizeof string - 2)) { return(err_listem); } *************** *** 250,256 **** currerr = errp->errno; first = Yes; } ! if ((stringlen = str_addarg(string, stringlen, errp->arg, first)) ==0) { return(err_listem); } --- 249,256 ---- currerr = errp->errno; first = Yes; } ! if (str_addarg(string, sizeof string, errp->arg, first) >= ! sizeof string) { return(err_listem); } *************** *** 258,267 **** } /* add final message */ ! stringlen = str_adderr(string, stringlen, currerr); /* return the error string */ ! return(stringlen == 0 ? err_listem : string); } /* --- 258,268 ---- } /* add final message */ ! if (str_adderr(string, sizeof string, currerr) >= sizeof string) ! return(err_listem); /* return the error string */ ! return(string); } /* *************** *** 269,293 **** * the string "str". */ ! static int str_adderr(str, len, err) char *str; ! int len; int err; { char *msg; ! int msglen; msg = err == 0 ? "Not a number" : strerror(err); ! msglen = strlen(msg) + 2; ! if (len <= msglen) ! { ! return(0); ! } ! (void) strcat(str, ": "); ! (void) strcat(str, msg); ! return(len - msglen); } /* --- 270,289 ---- * the string "str". */ ! static size_t str_adderr(str, len, err) char *str; ! size_t len; int err; { char *msg; ! size_t msglen; msg = err == 0 ? "Not a number" : strerror(err); ! if ((msglen = strlcat(str, ": ", len)) >= len) ! return(msglen); ! return(strlcat(str, msg, len)); } /* *************** *** 296,326 **** * is set (indicating that a comma should NOT be added to the front). */ ! static int str_addarg(str, len, arg, first) char *str; ! int len; char *arg; int first; { ! int arglen; - arglen = strlen(arg); if (!first) { ! arglen += 2; } ! if (len <= arglen) ! { ! return(0); ! } ! if (!first) ! { ! (void) strcat(str, ", "); ! } ! (void) strcat(str, arg); ! return(len - arglen); } /* --- 292,313 ---- * is set (indicating that a comma should NOT be added to the front). */ ! static size_t str_addarg(str, len, arg, first) char *str; ! size_t len; char *arg; int first; { ! size_t msglen; if (!first) { ! if ((msglen = strlcat(str, ", ", len)) >= len) ! return(msglen); } ! return(strlcat(str, arg, len)); } /*