diff options
author | gad <gad@FreeBSD.org> | 2001-07-15 00:57:18 +0000 |
---|---|---|
committer | gad <gad@FreeBSD.org> | 2001-07-15 00:57:18 +0000 |
commit | a76650f907e7aac1ed9e37f599a75de0160b55e3 (patch) | |
tree | 11cdd2e087078213c8cf31addfce31b3ffbb5026 /usr.sbin | |
parent | 75f5203b04d78ac555161bc219da58cbfeffefbd (diff) | |
download | FreeBSD-src-a76650f907e7aac1ed9e37f599a75de0160b55e3.zip FreeBSD-src-a76650f907e7aac1ed9e37f599a75de0160b55e3.tar.gz |
Replace three subtly-wrong calls to strncpy with calls to strlcpy, and
use (size_t) in a few places to avoid compile-time warnings on alpha.
MFC after: 1 week
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/lpr/common_source/common.c | 26 | ||||
-rw-r--r-- | usr.sbin/lpr/common_source/lp.h | 2 |
2 files changed, 13 insertions, 15 deletions
diff --git a/usr.sbin/lpr/common_source/common.c b/usr.sbin/lpr/common_source/common.c index 8c434b0..81b35ca 100644 --- a/usr.sbin/lpr/common_source/common.c +++ b/usr.sbin/lpr/common_source/common.c @@ -225,12 +225,11 @@ lock_file_name(const struct printer *pp, char *buf, size_t len) if (len == 0) len = MAXPATHLEN; - if (pp->lock_file[0] == '/') { - buf[0] = '\0'; - strncpy(buf, pp->lock_file, len); - } else { + if (pp->lock_file[0] == '/') + strlcpy(buf, pp->lock_file, len); + else snprintf(buf, len, "%s/%s", pp->spool_dir, pp->lock_file); - } + return buf; } @@ -244,18 +243,17 @@ status_file_name(const struct printer *pp, char *buf, size_t len) if (len == 0) len = MAXPATHLEN; - if (pp->status_file[0] == '/') { - buf[0] = '\0'; - strncpy(buf, pp->status_file, len); - } else { + if (pp->status_file[0] == '/') + strlcpy(buf, pp->status_file, len); + else snprintf(buf, len, "%s/%s", pp->spool_dir, pp->status_file); - } + return buf; } /* routine to get a current timestamp, optionally in a standard-fmt string */ void -lpd_gettime(struct timespec *tsp, char *strp, int strsize) +lpd_gettime(struct timespec *tsp, char *strp, size_t strsize) { struct timespec local_ts; struct timeval btime; @@ -312,7 +310,7 @@ lpd_gettime(struct timespec *tsp, char *strp, int strsize) strsize = TIMESTR_SIZE; strp[TIMESTR_SIZE+1] = '\0'; } - strncpy(strp, tempstr, strsize); + strlcpy(strp, tempstr, strsize); } /* routines for writing transfer-statistic records */ @@ -346,7 +344,7 @@ trstat_init(struct printer *pp, const char *fname, int filenum) /* get the starting time in both numeric and string formats, and * save those away along with the file-number */ pp->jobdfnum = filenum; - lpd_gettime(&pp->tr_start, pp->tr_timestr, TIMESTR_SIZE); + lpd_gettime(&pp->tr_start, pp->tr_timestr, (size_t)TIMESTR_SIZE); return; } @@ -367,7 +365,7 @@ trstat_write(struct printer *pp, tr_sendrecv sendrecv, size_t bytecnt, remspace = eostat - xStr; \ } while(0) - lpd_gettime(&pp->tr_done, NULL, 0); + lpd_gettime(&pp->tr_done, NULL, (size_t)0); trtime = DIFFTIME_TS(pp->tr_done, pp->tr_start); gethostname(thishost, sizeof(thishost)); diff --git a/usr.sbin/lpr/common_source/lp.h b/usr.sbin/lpr/common_source/lp.h index 0adf0fd..a2e0bff 100644 --- a/usr.sbin/lpr/common_source/lp.h +++ b/usr.sbin/lpr/common_source/lp.h @@ -262,7 +262,7 @@ void ldump(const char *_nfile, const char *_datafile, int _copies); void lastprinter(void); int lockchk(struct printer *_pp, char *_slockf); char *lock_file_name(const struct printer *_pp, char *_buf, size_t _len); -void lpd_gettime(struct timespec *_tsp, char *_strp, int _strsize); +void lpd_gettime(struct timespec *_tsp, char *_strp, size_t _strsize); int nextprinter(struct printer *_pp, int *_error); const char *pcaperr(int _error); |