examples/input-method: Don't crash on NULL surrounding text

E.g. With e.g. gnome-terminal we never end up in handle_surrouding
so it will be NULL.
This commit is contained in:
Guido Günther 2022-02-14 15:27:34 +01:00 committed by Simon Ser
parent 4741e9d841
commit 0a5a65cf48

View File

@ -194,7 +194,7 @@ static void do_updates(void) {
update_stage++; update_stage++;
break; break;
case 2: case 2:
if (strcmp(current.surrounding.text, "_Commit_") != 0) { if (current.surrounding.text && strcmp(current.surrounding.text, "_Commit_") != 0) {
return; return;
} }
zwp_input_method_v2_commit_string(input_method, "_CommitNoPreed_"); zwp_input_method_v2_commit_string(input_method, "_CommitNoPreed_");
@ -203,7 +203,7 @@ static void do_updates(void) {
update_stage++; update_stage++;
break; break;
case 3: case 3:
if (strcmp(current.surrounding.text, "_Commit__CommitNoPreed_") != 0) { if (current.surrounding.text && strcmp(current.surrounding.text, "_Commit__CommitNoPreed_") != 0) {
return; return;
} }
zwp_input_method_v2_commit_string(input_method, "_WaitNo_"); zwp_input_method_v2_commit_string(input_method, "_WaitNo_");
@ -212,7 +212,7 @@ static void do_updates(void) {
update_stage++; update_stage++;
break; break;
case 4: case 4:
if (strcmp(current.surrounding.text, "_Commit__WaitNo_") != 0) { if (current.surrounding.text && strcmp(current.surrounding.text, "_Commit__WaitNo_") != 0) {
return; return;
} }
zwp_input_method_v2_set_preedit_string(input_method, "PreedWithDel", strlen("Preed"), strlen("Preed")); zwp_input_method_v2_set_preedit_string(input_method, "PreedWithDel", strlen("Preed"), strlen("Preed"));
@ -221,7 +221,7 @@ static void do_updates(void) {
update_stage++; update_stage++;
break; break;
case 5: case 5:
if (strcmp(current.surrounding.text, "_Commit_") != 0) { if (current.surrounding.text && strcmp(current.surrounding.text, "_Commit_") != 0) {
return; return;
} }
zwp_input_method_v2_delete_surrounding_text(input_method, strlen("mit_"), 0); zwp_input_method_v2_delete_surrounding_text(input_method, strlen("mit_"), 0);
@ -229,7 +229,7 @@ static void do_updates(void) {
update_stage++; update_stage++;
break; break;
case 6: case 6:
if (strcmp(current.surrounding.text, "_Com") != 0) { if (current.surrounding.text && strcmp(current.surrounding.text, "_Com") != 0) {
printf("Failed\n"); printf("Failed\n");
} }
update_stage++; update_stage++;