Add dbPvt2Rec() cast

Reverse of dbRec2Pvt()

pacify -D_FORTIFY_SOURCE=3 and __builtin_object_size() as
"&precord->common" does not know than common as actually
the prefix of a variable sized struct.
This commit is contained in:
Michael Davidsaver
2024-06-14 14:49:30 -07:00
committed by Andrew Johnson
parent f9e53dded6
commit 3d70e70640
2 changed files with 23 additions and 5 deletions

View File

@@ -15,13 +15,21 @@ typedef struct dbCommonPvt {
/* Thread which is currently processing this record */
struct epicsThreadOSD* procThread;
struct dbCommon common;
/* actually followed by:
* struct dbCommon common;
*/
} dbCommonPvt;
static EPICS_ALWAYS_INLINE
dbCommonPvt* dbRec2Pvt(struct dbCommon *prec)
{
return CONTAINER(prec, dbCommonPvt, common);
return (dbCommonPvt*)((char*)prec - sizeof(dbCommonPvt));
}
static EPICS_ALWAYS_INLINE
dbCommon* dbPvt2Rec(struct dbCommonPvt *pvt)
{
return (dbCommon*)&pvt[1];
}
#endif // DBCOMMONPVT_H