/* Connection failed. Destroy the connection and signal an
* error. */
char buf[BLCKSZ];
- strncpy(buf, error_message, sizeof(buf)-1);
- buf[sizeof(buf) - 1] = '\0';
+ xstrncpy(buf, error_message, sizeof(buf));
if (P) {
/* storage for the error message gets erased when
* call PQfinish */
/* so we must temporarily stash it somewhere */
- strncpy(buf, PQerrorMessage(P), sizeof(buf)-1);
- buf[sizeof(buf) - 1] = '\0';
+ xstrncpy(buf, PQerrorMessage(P), sizeof(buf));
PQfinish(P);
}
error("libpq: %s", buf);
} else {
/* capture the error message before destroying the object */
char buf[BLCKSZ];
- strncpy(buf, error_message, sizeof(buf)-1);
- buf[sizeof(buf) - 1] = '\0';
+ xstrncpy(buf, error_message, sizeof(buf));
if (P) {
- strncpy(buf, PQerrorMessage(P), sizeof(buf)-1);
- buf[sizeof(buf) - 1] = '\0';
+ xstrncpy(buf, PQerrorMessage(P), sizeof(buf));
PQfinish(P);
}
error("libpq: %s", buf);
case PGRES_FATAL_ERROR:
tag = "fatal error [%s]";
err:
- strncpy(buf, PQresultErrorMessage(R),
+ xstrncpy(buf, PQresultErrorMessage(R),
sizeof(buf));
- buf[sizeof(buf) - 1] = '\0';
PQclear(R);
error(tag, buf);
/*NOTREACHED*/ default:
case PGRES_FATAL_ERROR:
tag = "fatal error [%s]";
err:
- strncpy(buf, PQresultErrorMessage(R), sizeof(buf));
- buf[sizeof(buf) - 1] = '\0';
+ xstrncpy(buf, PQresultErrorMessage(R), sizeof(buf));
PQclear(R);
error(tag, buf);
/*NOTREACHED*/ default: