diff options
| author | Noah Friedman | 2016-08-21 14:03:46 -0700 |
|---|---|---|
| committer | Noah Friedman | 2016-08-21 14:04:37 -0700 |
| commit | 7a6b3d0fb793864a1f5deb5a22de78a4dced652d (patch) | |
| tree | 2da0a23eff517e5b5aa8417936500b0586d98131 /src/xselect.c | |
| parent | 14a86f837762af8d16eef57c315da93b56699901 (diff) | |
| download | emacs-7a6b3d0fb793864a1f5deb5a22de78a4dced652d.tar.gz emacs-7a6b3d0fb793864a1f5deb5a22de78a4dced652d.zip | |
Fix interpretation of signed vs unsigned values when retrieving X
Window properties, and make sure the full value is returned when not
parsed.
New subr to export type and format information about X Window
properties to lisp.
* src/xselect.c (selection_data_to_lisp_data): Treat any data as
unsigned unless its actual type is INTEGER.
CARDINALs, in particular, are unsigned.
* src/xfns.c (Fx_change_window_property): If value is a string, ignore
any provided format and force to 8.
(x_window_property_intern): If returning value as a string, the length
is actual_size times the actual format of each element, which is not
necessarily bytes.
(Fx_window_property_attributes): New subr.
(syms_of_xfns): Declare it.
Diffstat (limited to 'src/xselect.c')
| -rw-r--r-- | src/xselect.c | 59 |
1 files changed, 47 insertions, 12 deletions
diff --git a/src/xselect.c b/src/xselect.c index 616d12c7cab..156888a540b 100644 --- a/src/xselect.c +++ b/src/xselect.c | |||
| @@ -1612,11 +1612,24 @@ selection_data_to_lisp_data (struct x_display_info *dpyinfo, | |||
| 1612 | /* Convert a single 16-bit number or a small 32-bit number to a Lisp_Int. | 1612 | /* Convert a single 16-bit number or a small 32-bit number to a Lisp_Int. |
| 1613 | If the number is 32 bits and won't fit in a Lisp_Int, | 1613 | If the number is 32 bits and won't fit in a Lisp_Int, |
| 1614 | convert it to a cons of integers, 16 bits in each half. | 1614 | convert it to a cons of integers, 16 bits in each half. |
| 1615 | |||
| 1616 | INTEGER is a signed type, CARDINAL is unsigned. | ||
| 1617 | Assume any other types are unsigned as well. | ||
| 1615 | */ | 1618 | */ |
| 1616 | else if (format == 32 && size == sizeof (int)) | 1619 | else if (format == 32 && size == sizeof (int)) |
| 1617 | return INTEGER_TO_CONS (((int *) data) [0]); | 1620 | { |
| 1621 | if (type == XA_INTEGER) | ||
| 1622 | return INTEGER_TO_CONS (((int *) data) [0]); | ||
| 1623 | else | ||
| 1624 | return INTEGER_TO_CONS (((unsigned int *) data) [0]); | ||
| 1625 | } | ||
| 1618 | else if (format == 16 && size == sizeof (short)) | 1626 | else if (format == 16 && size == sizeof (short)) |
| 1619 | return make_number (((short *) data) [0]); | 1627 | { |
| 1628 | if (type == XA_INTEGER) | ||
| 1629 | return make_number (((short *) data) [0]); | ||
| 1630 | else | ||
| 1631 | return make_number (((unsigned short *) data) [0]); | ||
| 1632 | } | ||
| 1620 | 1633 | ||
| 1621 | /* Convert any other kind of data to a vector of numbers, represented | 1634 | /* Convert any other kind of data to a vector of numbers, represented |
| 1622 | as above (as an integer, or a cons of two 16 bit integers.) | 1635 | as above (as an integer, or a cons of two 16 bit integers.) |
| @@ -1626,11 +1639,22 @@ selection_data_to_lisp_data (struct x_display_info *dpyinfo, | |||
| 1626 | ptrdiff_t i; | 1639 | ptrdiff_t i; |
| 1627 | Lisp_Object v = make_uninit_vector (size / 2); | 1640 | Lisp_Object v = make_uninit_vector (size / 2); |
| 1628 | 1641 | ||
| 1629 | for (i = 0; i < size / 2; i++) | 1642 | if (type == XA_INTEGER) |
| 1630 | { | 1643 | { |
| 1631 | short j = ((short *) data) [i]; | 1644 | for (i = 0; i < size / 2; i++) |
| 1632 | ASET (v, i, make_number (j)); | 1645 | { |
| 1633 | } | 1646 | short j = ((short *) data) [i]; |
| 1647 | ASET (v, i, make_number (j)); | ||
| 1648 | } | ||
| 1649 | } | ||
| 1650 | else | ||
| 1651 | { | ||
| 1652 | for (i = 0; i < size / 2; i++) | ||
| 1653 | { | ||
| 1654 | unsigned short j = ((unsigned short *) data) [i]; | ||
| 1655 | ASET (v, i, make_number (j)); | ||
| 1656 | } | ||
| 1657 | } | ||
| 1634 | return v; | 1658 | return v; |
| 1635 | } | 1659 | } |
| 1636 | else | 1660 | else |
| @@ -1638,11 +1662,22 @@ selection_data_to_lisp_data (struct x_display_info *dpyinfo, | |||
| 1638 | ptrdiff_t i; | 1662 | ptrdiff_t i; |
| 1639 | Lisp_Object v = make_uninit_vector (size / X_LONG_SIZE); | 1663 | Lisp_Object v = make_uninit_vector (size / X_LONG_SIZE); |
| 1640 | 1664 | ||
| 1641 | for (i = 0; i < size / X_LONG_SIZE; i++) | 1665 | if (type == XA_INTEGER) |
| 1642 | { | 1666 | { |
| 1643 | int j = ((int *) data) [i]; | 1667 | for (i = 0; i < size / X_LONG_SIZE; i++) |
| 1644 | ASET (v, i, INTEGER_TO_CONS (j)); | 1668 | { |
| 1645 | } | 1669 | int j = ((int *) data) [i]; |
| 1670 | ASET (v, i, INTEGER_TO_CONS (j)); | ||
| 1671 | } | ||
| 1672 | } | ||
| 1673 | else | ||
| 1674 | { | ||
| 1675 | for (i = 0; i < size / X_LONG_SIZE; i++) | ||
| 1676 | { | ||
| 1677 | unsigned int j = ((unsigned int *) data) [i]; | ||
| 1678 | ASET (v, i, INTEGER_TO_CONS (j)); | ||
| 1679 | } | ||
| 1680 | } | ||
| 1646 | return v; | 1681 | return v; |
| 1647 | } | 1682 | } |
| 1648 | } | 1683 | } |