From 96079f8c68c4a72e2ad62fc422f71148c49082d5 Mon Sep 17 00:00:00 2001 From: moozcheng <2601171134@qq.com> Date: Thu, 27 Jul 2023 15:09:31 +0800 Subject: [PATCH] dix: fix a misused const pointer in cursor.c `const CursorPtr` actually means `struct _Cursor *const`, a constant pointer, which does not prevent you from accidentally modifying the value it points to, like the cursor refcnt. Part-of: --- dix/cursor.c | 2 +- include/cursor.h | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dix/cursor.c b/dix/cursor.c index 94f1c044f..05e15ea69 100644 --- a/dix/cursor.c +++ b/dix/cursor.c @@ -145,7 +145,7 @@ UnrefCursor(CursorPtr cursor) } int -CursorRefCount(const CursorPtr cursor) +CursorRefCount(ConstCursorPtr cursor) { return cursor ? cursor->refcnt : 0; } diff --git a/include/cursor.h b/include/cursor.h index ad0269f1d..31bd5d20e 100644 --- a/include/cursor.h +++ b/include/cursor.h @@ -60,6 +60,11 @@ SOFTWARE. struct _DeviceIntRec; typedef struct _Cursor *CursorPtr; +// FUN FACT: If you typedef a pointer type, like the `CursorPtr` above +// then `const CursorPtr` or `CursorPtr const` actually means `struct _Cursor *const`, a constant pointer +// which is probably not what you want(a pointer to constant). +// Maybe better just keep the `*` around, or you have to typedef a separate constPtr type. +typedef struct _Cursor const *ConstCursorPtr; typedef struct _CursorMetric *CursorMetricPtr; extern _X_EXPORT CursorPtr rootCursor; @@ -69,7 +74,7 @@ extern _X_EXPORT int FreeCursor(void *pCurs, extern _X_EXPORT CursorPtr RefCursor(CursorPtr /* cursor */); extern _X_EXPORT CursorPtr UnrefCursor(CursorPtr /* cursor */); -extern _X_EXPORT int CursorRefCount(const CursorPtr /* cursor */); +extern _X_EXPORT int CursorRefCount(ConstCursorPtr /* cursor */); extern _X_EXPORT int AllocARGBCursor(unsigned char * /*psrcbits */ , unsigned char * /*pmaskbits */ ,