Skip to content

Commit d2e416a

Browse files
committed
fix pg_last_notice()
1 parent aa161f0 commit d2e416a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ext/pgsql/pgsql.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -877,9 +877,9 @@ static char *php_pgsql_PQescapeInternal(PGconn *conn, const char *str, size_t le
877877
#endif
878878

879879
/* {{{ _php_pgsql_trim_message */
880-
static char * _php_pgsql_trim_message(const char *message, int *len)
880+
static char * _php_pgsql_trim_message(const char *message, size_t *len)
881881
{
882-
register int i = strlen(message)-1;
882+
register size_t i = strlen(message)-1;
883883

884884
if (i>1 && (message[i-1] == '\r' || message[i-1] == '\n') && message[i] == '.') {
885885
--i;
@@ -964,7 +964,7 @@ static void _php_pgsql_notice_handler(void *resource_id, const char *message)
964964
TSRMLS_FETCH();
965965
if (! PGG(ignore_notices)) {
966966
notice = (php_pgsql_notice *)emalloc(sizeof(php_pgsql_notice));
967-
notice->message = _php_pgsql_trim_message(message, (int *)&notice->len);
967+
notice->message = _php_pgsql_trim_message(message, &notice->len);
968968
if (PGG(log_notices)) {
969969
php_error_docref(NULL TSRMLS_CC, E_NOTICE, "%s", notice->message);
970970
}
@@ -2305,18 +2305,23 @@ PHP_FUNCTION(pg_affected_rows)
23052305
Returns the last notice set by the backend */
23062306
PHP_FUNCTION(pg_last_notice)
23072307
{
2308-
zval *pgsql_link;
2308+
zval *pgsql_link = NULL;
23092309
PGconn *pg_link;
23102310
int id = -1;
23112311
php_pgsql_notice *notice;
23122312

23132313
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &pgsql_link) == FAILURE) {
23142314
return;
23152315
}
2316+
2317+
if (pgsql_link == NULL && id == -1) {
2318+
RETURN_FALSE;
2319+
}
2320+
23162321
/* Just to check if user passed valid resoruce */
23172322
ZEND_FETCH_RESOURCE2(pg_link, PGconn *, pgsql_link, id, "PostgreSQL link", le_link, le_plink);
23182323

2319-
if ((notice = zend_hash_index_find_ptr(&PGG(notices), Z_RES_HANDLE_P(pgsql_link))) == NULL) {
2324+
if ((notice = zend_hash_index_find_ptr(&PGG(notices), (zend_ulong)Z_RES_HANDLE_P(pgsql_link))) == NULL) {
23202325
RETURN_FALSE;
23212326
}
23222327
RETURN_STRINGL(notice->message, notice->len);

0 commit comments

Comments
 (0)