-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2: do not create uninitialized sway_keyboard #3189
base: master
Are you sure you want to change the base?
Conversation
It's not good to create a uninitialized struct, because it might become a possible error in future. I actually got hit by this while working on swaywm#3155 Signed-off-by: Konstantin Kharlamov <[email protected]>
I don't get this change. In both cases, |
calloc can't initialize struct fields correctly. For example, there was some pointer which was set to zero, whilst in properly configured keyboard it should've pointed to something, which led to a crash for me until I figured that just after This change makes sure that if we ever created a upd: s/uninitialized/partially uninitialized |
There's also a more general point (it doesn't immediately apply to this situation though) is that when you have two separate calls for struct creation and initialization, you need to create a temporary variable, and pass it between two calls. Often such design also makes problems with constifying variables. |
Seems like you're using overloaded terminology here. An uninitialized struct will have fields of indeterminate value. |
Ok, maybe I do. Although I'd argue there's little difference between a random value assigned to a field (i.e. uninitialized), and a wrong value assigned to the same field. But sure, a field initialized to wrong value is still initialized. Still, terminology doesn't make this pull request less useful.
keyboard->default_kbd_layout =
 sway_keyboard_get_layout(wlr_device->keyboard->xkb_state); The |
Is there any reason you can't move that code after |
I kind of did, the diff I referred to in my prev. comment have this code after the |
@remyabel I think you misunderstood me. The code I referred to works right now, I just showed the line that per my memory resulted in crash back when the line was inside the |
It's not good to create a uninitialized struct, because it might become
a possible error in future. I actually got hit by this while working on
#3155
v2: just move initialization inside the keyboard creation, leave the rest in place.