Simplify GetLockNameFromTagType.
authorRobert Haas <rhaas@postgresql.org>
Fri, 11 Mar 2016 02:37:22 +0000 (21:37 -0500)
committerRobert Haas <rhaas@postgresql.org>
Fri, 11 Mar 2016 02:37:22 +0000 (21:37 -0500)
The old code is wrong, because it returns a pointer to an automatic
variable.  And it's also more clever than we really need to be
considering that the case it's worrying about should never happen.

src/backend/storage/lmgr/lmgr.c

index 9d2663e2f9d6da9b209d050394f101852fa15eae..0632fc009e586d46331d22eceb6c09f605110c96 100644 (file)
@@ -1003,17 +1003,7 @@ DescribeLockTag(StringInfo buf, const LOCKTAG *tag)
 const char *
 GetLockNameFromTagType(uint16 locktag_type)
 {
-   const char *locktypename;
-   char        tnbuf[32];
-
-   if (locktag_type <= LOCKTAG_LAST_TYPE)
-       locktypename = LockTagTypeNames[locktag_type];
-   else
-   {
-       snprintf(tnbuf, sizeof(tnbuf), "unknown %d",
-                (int) locktag_type);
-       locktypename = tnbuf;
-   }
-
-   return locktypename;
+   if (locktag_type > LOCKTAG_LAST_TYPE)
+       return "???";
+   return LockTagTypeNames[locktag_type];
 }