signed vs. unsigned in plpy_procedure.c

Started by Andres Freundover 12 years ago2 messages
#1Andres Freund
andres@2ndquadrant.com
1 attachment(s)

Hi,

src/postgresql/src/pl/plpython/plpy_procedure.c: In function ‘PLy_procedure_munge_source’:
src/postgresql/src/pl/plpython/plpy_procedure.c:507:2: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
Assert(plen >= 0 && plen < mlen);

Which has a point, we assign sprintf()s result to a size_t and then
check for a negative value. Which doesn't work.

Obviously the impact is miniscule, but removing legitimate warnings is a
good thing. Trivial patch attached.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

plpy_procedure_unsigned.patchtext/x-patch; charset=us-asciiDownload
diff --git a/src/pl/plpython/plpy_procedure.c b/src/pl/plpython/plpy_procedure.c
index 5007e77..d278d6e 100644
--- a/src/pl/plpython/plpy_procedure.c
+++ b/src/pl/plpython/plpy_procedure.c
@@ -494,8 +494,8 @@ PLy_procedure_munge_source(const char *name, const char *src)
 	char	   *mrc,
 			   *mp;
 	const char *sp;
-	size_t		mlen,
-				plen;
+	size_t		mlen;
+	int			plen;
 
 	/*
 	 * room for function source and the def statement
#2Heikki Linnakangas
hlinnakangas@vmware.com
In reply to: Andres Freund (#1)
Re: signed vs. unsigned in plpy_procedure.c

On 02.07.2013 13:39, Andres Freund wrote:

src/postgresql/src/pl/plpython/plpy_procedure.c: In function �PLy_procedure_munge_source�:
src/postgresql/src/pl/plpython/plpy_procedure.c:507:2: warning: comparison of unsigned expression>= 0 is always true [-Wtype-limits]
Assert(plen>= 0&& plen< mlen);

Which has a point, we assign sprintf()s result to a size_t and then
check for a negative value. Which doesn't work.

Obviously the impact is miniscule, but removing legitimate warnings is a
good thing. Trivial patch attached.

Thanks, applied.

- Heikki

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers