enhance code for some uninitialized fields

This commit is contained in:
Vincent Wei
2022-09-23 11:20:50 +08:00
parent dfc7e95fcd
commit 9a94fb9a7c
6 changed files with 16 additions and 10 deletions

View File

@@ -149,7 +149,7 @@ typedef struct _ZORDERINFO {
#ifdef _MGRM_THREADS
# ifdef __ZI_USE_RWLOCK
pthread_rwlock_t rwlock;
pthread_t wrlock_owner;
pthread_t rwlock_owner;
# else
pthread_mutex_t mutex;
# endif

View File

@@ -601,18 +601,18 @@ static void reset_window (PMAINWIN pWin, RECT* rcWin)
static inline void lock_zi_for_change (ZORDERINFO* zi)
{
pthread_rwlock_wrlock(&zi->rwlock);
zi->wrlock_owner = pthread_self();
zi->rwlock_owner = pthread_self();
}
static inline void unlock_zi_for_change (ZORDERINFO* zi)
{
pthread_rwlock_unlock(&zi->rwlock);
zi->wrlock_owner = 0;
zi->rwlock_owner = 0;
}
static inline void lock_zi_for_read (ZORDERINFO* zi)
{
if (zi->wrlock_owner == pthread_self()) {
if (zi->rwlock_owner == pthread_self()) {
return;
}
@@ -621,7 +621,7 @@ static inline void lock_zi_for_read (ZORDERINFO* zi)
static inline void unlock_zi_for_read (ZORDERINFO* zi)
{
if (zi->wrlock_owner == pthread_self()) {
if (zi->rwlock_owner == pthread_self()) {
return;
}

View File

@@ -245,6 +245,7 @@ int __kernel_alloc_z_order_info (int nr_topmosts, int nr_normals, BOOL with_mask
#ifdef _MGRM_THREADS
# ifdef __ZI_USE_RWLOCK
pthread_rwlock_init(&__mg_zorder_info->rwlock, NULL);
__mg_zorder_info->rwlock_owner = 0;
# else
do {
int ret;

View File

@@ -187,7 +187,8 @@ int __mg_bmp_compute_pitch(int bpp, Uint32 width, Uint32 *pitch, BOOL does_round
return bytespp;
}
void* GUIAPI InitMyBitmapSL (MG_RWops* area, const char* ext, MYBITMAP* my_bmp, RGB* pal)
void* GUIAPI
InitMyBitmapSL (MG_RWops* area, const char* ext, MYBITMAP* my_bmp, RGB* pal)
{
int type;
LOAD_MYBITMAP_INFO* load_info;
@@ -209,8 +210,11 @@ void* GUIAPI InitMyBitmapSL (MG_RWops* area, const char* ext, MYBITMAP* my_bmp,
my_bmp->frames = 1;
my_bmp->depth = GetGDCapability (HDC_SCREEN, GDCAP_BPP) << 3;
// initialize the palette with the screen palette.
if (my_bmp->depth <= 8)
GetPalette (HDC_SCREEN, 0, 256, (GAL_Color*)pal);
else
memset (pal, 0, sizeof(RGB) * 256); // reset the palette.
/* This is just for gray screen. If your screen is gray,
* please define this macro _GRAY_SCREEN.

View File

@@ -148,14 +148,15 @@ static BOOL find_color_key (GAL_PixelFormat* format, const MYBITMAP* my_bmp,
goto free_and_ret;
color_num = 1 << my_bmp->depth;
pixels = malloc (color_num * sizeof (Uint32));
for (i = 0; i < color_num; i++)
pixels = calloc (color_num, sizeof (Uint32));
for (i = 0; i < color_num; i++) {
pixels[i] = GAL_MapRGB (format, pal[i].r, pal[i].g, pal[i].b);
}
pixel_key = pixels [my_bmp->transparent];
for (i = 0; i < color_num; i++) {
if (pixels[i] == pixel_key && i != my_bmp->transparent)
break;
break;
}
if (i == color_num)

View File

@@ -1001,7 +1001,7 @@ static inline MYBMP_WITH_PAL* new_mybmp_with_pal (void)
MYBMP_WITH_PAL* mybmp_pal;
mybmp_pal = NEW(MYBMP_WITH_PAL);
mybmp_pal->pal = malloc (sizeof (RGB) * 256);
mybmp_pal->pal = calloc (256, sizeof (RGB));
return mybmp_pal;
}