Skip to content

bug fix on remove first keyborad layout #205

@killghost

Description

@killghost

in function refresh_locale_list

if user delete first keyboardlayout, locale_previous will nullptr.

right code is the next :

// Go though the linked list and remove KeyboardLocale's that are
// no longer loaded.
while (locale_item != NULL) {
// Check to see if the old HKL is in the new list.
bool is_loaded = false;
for (int i = 0; i < new_size && !is_loaded; i++) {
if (locale_item->id == hkl_list[i]) {
// Flag and jump out of the loop.
hkl_list[i] = NULL;
is_loaded = true;
}
}

            if (is_loaded) {
                logger(LOG_LEVEL_DEBUG, "%s [%u]: Found locale ID %#p in the cache.\n",
                        __FUNCTION__, __LINE__, locale_item->id);

                // Set the previous local to the current locale.
                locale_previous = locale_item;

                // Check and see if the locale is our current active locale.
                if (locale_item->id == hlk_focus) {
                    locale_current = locale_item;
                }

                count++;

				// Iterate to the next linked list item.
				locale_item = locale_item->next;
            } else {
                logger(LOG_LEVEL_DEBUG, "%s [%u]: Removing locale ID %#p from the cache.\n",
                        __FUNCTION__, __LINE__, locale_item->id);

				// Make sure the locale_current points NULL or something valid.
                if (locale_item == locale_current) {
                    locale_current = NULL;
                }

                //FIXME.
				// this line code equal locale_previous == NULL
				if (locale_item == locale_first)
				{
					KeyboardLocale* locale_temp = locale_item->next;

					// Free the memory used by locale_item;
					free(locale_item);

					locale_first = locale_temp;
					locale_item = locale_temp;
				}
				else
				{
					// If the old id is not in the new list, remove it.
					locale_previous->next = locale_item->next;

					// Free the memory used by locale_item;
					free(locale_item);

					// Iterate to the next linked list item.
					locale_item = locale_previous->next;
				}
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions