summaryrefslogtreecommitdiff
path: root/src
Commit message (Collapse)AuthorAgeFilesLines
...
* keysym: handle ssharp in XConvertCase()Peter Hutterer2019-12-221-0/+4
| | | | | | | | | | | | | | | | | | | | | lowercase: LATIN SMALL LETTER SHARP S (U+00DF) uppercase: LATIN CAPITAL LETTER SHARP S (U+1E9E) The uppercase sharp s (XK_ssharp) is a relatively recent addition to unicode but was added to the relevant keyboard layouts in xkeyboard-config-2.25 (d1411e5e95c) https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/issues/144 Alas, the CapsLock behavior was broken on the finnish layout (maybe others). This was due XConvertCase() never returning the uppercase characters. Let's make this function return the right lower/upper symbols for the sharp s and hope that the world won't get any worse because of it. Corresponding Xlib issue: https://gitlab.freedesktop.org/xorg/lib/libx11/issues/110 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* parser: fix the remaining pointer chasingRan Benita2019-12-141-22/+21
| | | | | | Fix the TODO added in 7c42945. Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: fix quadratic pointer chasingRan Benita2019-11-143-61/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the AST, lists (e.g. the list of statements in a file) are kept in singly-linked lists -- each AST node has a `next` pointer available for this purpose. Previously, a node was added to the list by starting from the head, chasing to the last, and appending. So creating a list of length N would take ~N^2/2 pointer dereferences. Now, we always (temporarily) keep the last as well, so appending is O(1) instead of O(N). Given a keymap xkb_keymap { xkb_keycodes { minimum = 8; minimum = 8; minimum = 8; minimum = 8; minimum = 8; [... repeated N times ...] }; xkb_types {}; xkb_compat {}; xkb_symbols {}; }; The compilation times are N | Before | After --------|----------|------- 10,000 | 0.407s | 0.006s 20,000 | 1.851s | 0.015s 30,000 | 5.737s | 0.021s 40,000 | 12.759s | 0.023s 50,000 | 21.489s | 0.035s 60,000 | 40.473s | 0.041s 70,000 | 53.336s | 0.039s 80,000 | 72.485s | 0.044s 90,000 | 94.703s | 0.048s 100,000 | 118.390s | 0.057s Another option is to ditch the linked lists and use arrays instead. I got it to work, but its more involved and allocation heavy so turns out to be worse without further optimizations. Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: remove an unneeded checkRan Benita2019-11-141-7/+2
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* compat: reject interpret modifier predicate with more than one valueRan Benita2019-11-121-1/+1
| | | | | | | | | | Given interpret ISO_Level3_Shift+AnyOf(all,extraneous) { ... }; Previously, extraneous (and further) was ignored. Now it's rejected. Signed-off-by: Ran Benita <ran@unusedvar.com>
* expr: fix log message on some unexpected expression typesRan Benita2019-11-121-0/+6
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* Replace some tabs that sneaked in with spacesRan Benita2019-11-122-6/+6
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: fix merge mode only applied to first vmod in a virtual_modifiers ↵Ran Benita2019-11-121-1/+2
| | | | | | | | | | | | | | | | | | | | | | statement Given augment virtual_modifiers NumLock,Alt,LevelThree Previously it was expanded (directly in the parser) to augment virtual_modifiers NumLock; virtual_modifiers Alt; virtual_modifiers LevelThree; Now it expands to augment virtual_modifiers NumLock; augment virtual_modifiers Alt; augment virtual_modifiers LevelThree; Signed-off-by: Ran Benita <ran@unusedvar.com>
* ast: use a separate expr struct for action listRan Benita2019-11-125-4/+28
| | | | | | Currently it's under UnaryExpr, which just doesn't make sense. Signed-off-by: Ran Benita <ran@unusedvar.com>
* ast-build: get rid of unhelpful macroRan Benita2019-11-121-17/+36
| | | | | | Straightforward code is better here. Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: a string is greater than its prefixRan Benita2019-11-091-8/+8
| | | | | | Bug accidentally introduced in 9a92b46. Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: combine atom_intern() and atom_lookup()Ran Benita2019-11-093-34/+7
| | | | | | Use an "add" bool parameter instead. This simplifies the code a bit. Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: correct iteration count in hash functionRan Benita2019-11-091-1/+1
| | | | | | | Fixup of ccab349 - unlike the commit message, hash a byte twice instead of zero times, which is probably better. This is how it was before. Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: describe how this odd data structure worksRan Benita2019-11-091-0/+17
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: use a better hash functionRan Benita2019-11-091-5/+15
| | | | | | | | | FNV-1a instead of the djb2-like one from before. Keep the unrolling since it seems quite beneficial, even though it loses one byte if the length is odd... Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: style changesRan Benita2019-11-091-21/+11
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: remove handling of garbage inputRan Benita2019-11-091-11/+2
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: use explicit size for fingerprintRan Benita2019-11-091-4/+4
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: replace an avoidable strlenRan Benita2019-11-091-1/+1
| | | | Signed-off-by: Ran Benita <ran@unusedvar.com>
* atom: remove redundant fieldRan Benita2019-11-091-4/+3
| | | | | | | | The field is redundant. Due to alignment, this will only save memory on 32bit architectures. Signed-off-by: Ran Benita <ran@unusedvar.com>
* parser: get rid of "stealing" atomsRan Benita2019-11-085-35/+8
| | | | | | | | | This requires (well, at least implemented by) casting away `const` which is undefined behavior, and clang started to warn about it. The micro optimization didn't save too many allocations, anyway. Signed-off-by: Ran Benita <ran@unusedvar.com>
* Use XDG_CONFIG_HOME as first XKB search pathPeter Hutterer2019-10-311-1/+18
| | | | | | | | | | | | | Use $XDG_CONFIG_HOME/xkb as the primary lookup path for XKB rules. Same motivation as in 3a91788d9254b, however the XDG directories are more standard and recommended these days than application-specific dotfiles. The XDG spec says to fall back to $HOME/.config where XDG_CONFIG_HOME is not set so we implement that behavior as well. Fixes #112 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* context: Don't fail to create the context if HOME isn't availableJan Alexander Steffens (heftig)2019-10-201-7/+7
| | | | | | | | | E.g. when Mutter has CAP_SYS_NICE and thus secure_getenv returns NULL. Fixes https://bugs.archlinux.org/task/64191 [ran: changed to ignore error] Signed-off-by: Ran Benita <ran@unusedvar.com>
* keymap-dump: use consistent capitalization for "Group<N>"Ran Benita2019-10-161-2/+2
| | | | | | It's used capitalized everywhere except a couple places. Signed-off-by: Ran Benita <ran@unusedvar.com>
* keymap-dump: fix invalid names used for levels above 8Ran Benita2019-10-161-2/+2
| | | | | | | | | | | | xkbcomp only accepts the "Level" prefix for a level name for levels 1 to 8, but the keymap dumping code added it always, e.g. "Level15". The plain integer, e.g. "8", "15" is always accepted, so just use that. Fixes https://github.com/xkbcommon/libxkbcommon/issues/113 Signed-off-by: Ran Benita <ran@unusedvar.com> Reported-by: progandy
* context: move ~/.xkb to before XKB_CONFIG_ROOT in the default include pathRan Benita2019-10-031-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the default include path was XKB_CONFIG_ROOT:~/.xkb. The ~/.xkb include path is intended to allow the local user to customize their keymaps without having to modify system paths. But usually, the user only wants to customize specific parts. When XKB_CONFIG_ROOT is first, the user can only customize through the "entry point" (the RMLVO). When ~/.xkb is first, the user can drop in a file and it will override the system one. The impetus for this change is the rules file. "evdev" is hard-coded everywhere, so it not often not possible to change to something else. And the rules files determines how the rest of the RMLVO is interpreted. So, to enable customization, we have these options: A: System includes user. B: User includes system. C: Library goes over both in one or the other order. Option A is problematic due to backward compatibility and is also unnatural. Option B gives the user control and is backward compatible, so that's what we choose. This is also how Compose files are handled, and that seems to work fine in the wild. Option C is actually less flexible than B, and more complicated. (The rules file format doesn't have an include statement yet, but it's planned). Signed-off-by: Ran Benita <ran@unusedvar.com>
* Use bitwise test instead of popcount to check if one bit is setMichael Forney2019-06-102-11/+3
| | | | | | | | | | | We don't need to determine the total number of bits set to determine if exactly one is set. Additionally, on x86_64 without any -march=* flag, __builtin_popcount will get compiled to a function call to the compiler runtime (on gcc), or a long sequence of bit operations (on clang). Signed-off-by: Michael Forney <mforney@mforney.org>
* symbols: add a comment to suppress warning from code analyzersKonstantin Kharlamov2019-03-231-0/+3
| | | | Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
* Sync Keysyms with recent xproto additionsHans de Goede2019-01-221-241/+247
| | | | | | | | | | | xproto recently has been extended with 2 new keysyms: XF86XK_MonBrightnessCycle XF86XK_RotationLockToggle This commit is the result of running "scripts/update-keysyms" on a system with the updated xproto installed. Signed-off-by: Hans de Goede <hdegoede@redhat.com>
* Fix off-by-one error in index check in xkb_file_type_to_stringAlan Coopersmith2018-09-301-1/+1
| | | | | | | | | | | Found by Oracle's Parfait 2.2 static analyzer: Error: Buffer overrun Read outside array bounds [read-outside-array-bounds] (CWE 125): In array dereference of xkb_file_type_strings[type] with index type Array size is 56 bytes, index <= 56 at line 734 of src/xkbcomp/ast-build.c in function 'xkb_file_type_to_string'. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
* darray: fix unprotected macro argumentRan Benita2018-08-241-1/+1
| | | | | Reported-by: @msmeissn Signed-off-by: Ran Benita <ran234@gmail.com>
* x11: fix undefined behavior when copying the coordinates of ptr movements ↵Ran Benita2018-08-181-2/+2
| | | | | | | | | | actions Left shift of a negative integer. For some reason the protocol representation here got really botched (in the spec it is just a nice and simple INT16). Signed-off-by: Ran Benita <ran234@gmail.com>
* Fail expression lookup on invalid atomsDaniel Stone2018-08-031-1/+5
| | | | | | | If we fail atom lookup, then we should not claim that we successfully looked up the expression. Signed-off-by: Daniel Stone <daniels@collabora.com>
* Fix signed vs. unsigned confusion in name sanitisationDaniel Stone2018-08-031-1/+2
| | | | | | | Don't try to divide through a signed char when indexing an array, lest ye try to index off the start of it. Signed-off-by: Daniel Stone <daniels@collabora.com>
* darray: Don't call memcpy() on NULLDaniel Stone2018-08-031-1/+2
| | | | | | | The only time we could ever hit this was with count == 0, which seems unnecessarily pedantic. But OK. Signed-off-by: Daniel Stone <daniels@collabora.com>
* text: NULL-terminate SI mask namesDaniel Stone2018-08-031-0/+1
| | | | | | | | The list should have a NULL sentry. Add one. testcase: 'interpret KP_Delete+AnyOfOrNaneo(ll)' Signed-off-by: Daniel Stone <daniels@collabora.com>
* xkbcomp: Don't falsely promise from ExprResolveLhsDaniel Stone2018-08-031-1/+1
| | | | | | | | | | Every user of ExprReturnLhs goes on to unconditionally dereference the field return, which can be NULL if xkb_intern_atom fails. Return false if this is the case, so we fail safely. testcase: splice geometry data into interp Signed-off-by: Daniel Stone <daniels@collabora.com>
* xkbcomp: Don't explode on invalid virtual modifiersDaniel Stone2018-08-031-0/+2
| | | | | | testcase: 'virtualModifiers=LevelThreC' Signed-off-by: Daniel Stone <daniels@collabora.com>
* xkbcomp: Don't crash on no-op modmask expressionsDaniel Stone2018-08-031-1/+2
| | | | | | | If we have an expression of the form 'l1' in an interp section, we unconditionally try to dereference its args, even if it has none. Signed-off-by: Daniel Stone <daniels@collabora.com>
* parser: Don't set more maps when we don't have anyDaniel Stone2018-08-031-2/+3
| | | | | | | | | | If the scanner indicates that we might have something which looks like a map, but the parser in fact fails to create that map, we will try to access the map regardless. Stop doing that. testcase: 'xkb_keymap {' -> '#kb_keymap' Signed-off-by: Daniel Stone <daniels@collabora.com>
* action: make a note that we may not null-terminate private stringsPeter Hutterer2018-08-011-0/+1
| | | | | | | | | | | | | | Coverity complains that a 7-byte string may not be null-terminated when copied into act->data (size 7). This is fine, make a note of it. All the strings in xkeyboard-config only use 6 bytes + null terminator so this won't be an issue. The server (the only user of these) uses an 8-byte array and forcibly null-terminates the string, see XkbDDXPrivate(). Everything else treats it as byte-array size 7 anyway so whether it's null-terminated doesn't matter. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* xkbcomp: fix pointer value for FreeStmtPeter Hutterer2018-08-011-1/+1
| | | | Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* keycodes: don't try to copy zero key aliasesPeter Hutterer2018-08-011-7/+7
| | | | | | | | | | | Move the aliases copy to within the (num_key_aliases > 0) block. Passing info->aliases into this fuction with invalid aliases will cause log messages but num_key_aliases stays on 0. The key_aliases array is never allocated and remains NULL. We then loop through the aliases, causing a null-pointer dereference. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* text: init the target buffer to zeroPeter Hutterer2018-08-011-1/+1
| | | | | | | | There's a (theoretical?) path where we might end up strcpy() buf without ever writing to it. This happens if the mask is nonzero but specifies a modifier larger than the one in the xkb_mod_set. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
* compose: fix infinite loop in parser on some inputsRan Benita2018-07-301-1/+1
| | | | | | | | | The parser would enter an infinite loop if an unterminated keysym literal occurs at EOF. Found with the afl fuzzer. Signed-off-by: Ran Benita <ran234@gmail.com>
* xkbcomp: fix crash when parsing an xkb_geometry sectionRan Benita2018-07-302-10/+8
| | | | | | | | | | | xkb_geometry sections are ignored; previously the had done so by returning NULL for the section's XkbFile, however some sections of the code do not expect this. Instead, create an XkbFile for it, it will never be processes and discarded later. Caught with the afl fuzzer. Signed-off-by: Ran Benita <ran234@gmail.com>
* xkbcomp: fix crashes in the parser when geometry tokens appearRan Benita2018-07-304-5/+23
| | | | | | | | | | | | | | | | In the XKB format, floats and various keywords can only be used in the xkb_geometry section. xkbcommon removed support xkb_geometry, but still parses it for backward compatibility. As part of ignoring it, the float AST node and various keywords were removed, and instead NULL was returned by their parsing actions. However, the rest of the code does not handle NULLs, and so when they appear crashes usually ensue. To fix this, restore the float AST node and the ignored keywords. None of the evaluating code expects them, so nice error are displayed. Caught with the afl fuzzer. Signed-off-by: Ran Benita <ran234@gmail.com>
* xkbcomp: fix stack overflow when evaluating boolean negationRan Benita2018-07-301-1/+1
| | | | | | | | | | | | | The expression evaluator would go into an infinite recursion when evaluating something like this as a boolean: `!True`. Instead of recursing to just `True` and negating, it recursed to `!True` itself again. Bug inherited from xkbcomp. Caught with the afl fuzzer. Signed-off-by: Ran Benita <ran234@gmail.com>
* keysym-utf: reject out-of-range Unicode codepoints in xkb_keysym_to_utf{8,32}Ran Benita2018-06-232-10/+12
| | | | | | | | | | It used to be UTF-8 was defined for inputs > 0x10FFFF, but nowadays that's the maximum and a codepoint is encoded up to 4 bytes, not 6. Fixes: https://github.com/xkbcommon/libxkbcommon/issues/58 Fixes: https://github.com/xkbcommon/libxkbcommon/issues/59 Reported-by: @andrecbarros Signed-off-by: Ran Benita <ran234@gmail.com>
* keysym-utf: replace the Unicode characters for leftanglebracket and ↵Ran Benita2018-02-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | rightanglebracket Looking at leftanglebracket - The standard[1] does not specify any Unicode value for it. - The keysym list keysymdef.h in x11proto[2] says U+27E9 MATHEMATICAL RIGHT ANGLE BRACKET in a comment. - The keysym->unicode list in xkbcommon which comes from [3] has U+2329 LEFT-POINTING ANGLE BRACKET. - The keysym->unicode list in Xlib[4] has U+2039 SINGLE LEFT-POINTING ANGLE QUOTATION MARK. [1] https://www.x.org/releases/X11R7.7/doc/xproto/x11protocol.html#Legacy_KEYSYMs [2] https://cgit.freedesktop.org/xorg/proto/x11proto/tree/keysymdef.h [3] https://www.cl.cam.ac.uk/%7Emgk25/ucs/keysym2ucs.c [4] https://cgit.freedesktop.org/xorg/lib/libX11/tree/src/xlibi18n/imKStoUCS.c The symbols we are using, {LEFT,RIGHT}-POINTING ANGLE BRACKET, are deprecated according to Unicode[5]: These characters are deprecated and are strongly discouraged for mathematical use because of their canonical equivalence to CJK punctuation. [5] https://www.unicode.org/charts/PDF/U2300.pdf Hence, switch to the MATHEMATICAL codepoints which seem to be the best fit. Fixes: https://github.com/xkbcommon/libxkbcommon/issues/47 Reported-by: @bytensky Signed-off-by: Ran Benita <ran234@gmail.com>