[1/4] Check query return value in pkgbase_user_notify()

Message ID 20170418065254.8200-1-lfleischer@archlinux.org
State Accepted, archived
Headers show
Series [1/4] Check query return value in pkgbase_user_notify() | expand

Commit Message

Lukas Fleischer April 18, 2017, 6:52 a.m. UTC
Instead of unconditionally calling fetch on the return value of query(),
error out early if the value evaluates to false.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
---
 web/lib/pkgbasefuncs.inc.php | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Patch

diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php
index cd4b271..57933e8 100644
--- a/web/lib/pkgbasefuncs.inc.php
+++ b/web/lib/pkgbasefuncs.inc.php
@@ -852,12 +852,11 @@  function pkgbase_user_notify($uid, $base_id) {
 	$q.= " AND PackageBaseID = " . $dbh->quote($base_id);
 	$result = $dbh->query($q);
 
-	if ($result->fetch(PDO::FETCH_NUM)) {
-		return true;
-	}
-	else {
+	if (!$result) {
 		return false;
 	}
+
+	return ($result->fetch(PDO::FETCH_NUM) > 0);
 }
 
 /**