xserver: Branch 'master'
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Sun Sep 1 22:51:26 UTC 2024
dix/cursor.c | 2 +-
include/cursor.h | 7 ++++++-
2 files changed, 7 insertions(+), 2 deletions(-)
New commits:
commit 96079f8c68c4a72e2ad62fc422f71148c49082d5
Author: moozcheng <2601171134 at qq.com>
Date: Thu Jul 27 15:09:31 2023 +0800
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: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1140>
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 */ ,
More information about the xorg-commit
mailing list