diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-16 02:22:30 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-07-16 02:22:30 (GMT) |
commit | 4b0a315c3179c1785fcec6857ed4a69417fd7ae8 (patch) | |
tree | 6d8452c61091f295b61c7c307949df5dad942111 /Objects | |
parent | c0cde4da2a3d7992b7405ed5e11bc43f7d2391a0 (diff) | |
download | cpython-4b0a315c3179c1785fcec6857ed4a69417fd7ae8.zip cpython-4b0a315c3179c1785fcec6857ed4a69417fd7ae8.tar.gz cpython-4b0a315c3179c1785fcec6857ed4a69417fd7ae8.tar.bz2 |
Use sizeof(buffer) instead of duplicating the constants to ensure they won't
be wrong.
The real change is to pass (bufsz - 1) to PyOS_ascii_formatd and 1
to strncat. strncat copies n+1 bytes from src (not dest).
Reported by Klocwork #58.
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/complexobject.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c index 4c6ea39..0d37fb2 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -274,16 +274,16 @@ complex_to_buf(char *buf, int bufsz, PyComplexObject *v, int precision) { char format[32]; if (v->cval.real == 0.) { - PyOS_snprintf(format, 32, "%%.%ig", precision); - PyOS_ascii_formatd(buf, bufsz, format, v->cval.imag); - strncat(buf, "j", bufsz); + PyOS_snprintf(format, sizeof(format), "%%.%ig", precision); + PyOS_ascii_formatd(buf, bufsz - 1, format, v->cval.imag); + strncat(buf, "j", 1); } else { char re[64], im[64]; /* Format imaginary part with sign, real part without */ - PyOS_snprintf(format, 32, "%%.%ig", precision); - PyOS_ascii_formatd(re, 64, format, v->cval.real); - PyOS_snprintf(format, 32, "%%+.%ig", precision); - PyOS_ascii_formatd(im, 64, format, v->cval.imag); + PyOS_snprintf(format, sizeof(format), "%%.%ig", precision); + PyOS_ascii_formatd(re, sizeof(re), format, v->cval.real); + PyOS_snprintf(format, sizeof(format), "%%+.%ig", precision); + PyOS_ascii_formatd(im, sizeof(im), format, v->cval.imag); PyOS_snprintf(buf, bufsz, "(%s%sj)", re, im); } } |