提交 33317310 编写于 作者: B Behdad Esfahbod

Fix sign of shift operators

This one:

  map->mask = (1 << (next_bit + bits_needed)) - (1 << next_bit);

before the fix, the shift was done as an int, causing overflow
if it ever got to 1 << 31.  Sprinkle 'u's around.

Fixes https://bugs.chromium.org/p/chromium/issues/detail?id=634805
上级 10a0d4aa
......@@ -134,7 +134,7 @@ struct hb_buffer_t {
#ifndef HB_NDEBUG
unsigned int end = start + count;
assert (end <= 8);
unsigned int bits = (1<<end) - (1<<start);
unsigned int bits = (1u<<end) - (1u<<start);
assert (0 == (allocated_var_bits & bits));
allocated_var_bits |= bits;
#endif
......@@ -144,7 +144,7 @@ struct hb_buffer_t {
#ifndef HB_NDEBUG
unsigned int end = start + count;
assert (end <= 8);
unsigned int bits = (1<<end) - (1<<start);
unsigned int bits = (1u<<end) - (1u<<start);
assert (bits == (allocated_var_bits & bits));
allocated_var_bits &= ~bits;
#endif
......@@ -154,7 +154,7 @@ struct hb_buffer_t {
#ifndef HB_NDEBUG
unsigned int end = start + count;
assert (end <= 8);
unsigned int bits = (1<<end) - (1<<start);
unsigned int bits = (1u<<end) - (1u<<start);
assert (bits == (allocated_var_bits & bits));
#endif
}
......
......@@ -45,11 +45,11 @@ struct hb_cache_t
inline bool get (unsigned int key, unsigned int *value)
{
unsigned int k = key & ((1<<cache_bits)-1);
unsigned int k = key & ((1u<<cache_bits)-1);
unsigned int v = values[k];
if ((v >> value_bits) != (key >> cache_bits))
return false;
*value = v & ((1<<value_bits)-1);
*value = v & ((1u<<value_bits)-1);
return true;
}
......@@ -57,14 +57,14 @@ struct hb_cache_t
{
if (unlikely ((key >> key_bits) || (value >> value_bits)))
return false; /* Overflows */
unsigned int k = key & ((1<<cache_bits)-1);
unsigned int k = key & ((1u<<cache_bits)-1);
unsigned int v = ((key>>cache_bits)<<value_bits) | value;
values[k] = v;
return true;
}
private:
unsigned int values[1<<cache_bits];
unsigned int values[1u<<cache_bits];
};
typedef hb_cache_t<21, 16, 8> hb_cmap_cache_t;
......
......@@ -725,7 +725,7 @@ _hb_coretext_shape (hb_shape_plan_t *shape_plan,
pchars[chars_len++] = 0xFFFDu;
else {
pchars[chars_len++] = 0xD800u + ((c - 0x10000u) >> 10);
pchars[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1 << 10) - 1));
pchars[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1u << 10) - 1));
}
}
......
......@@ -586,7 +586,7 @@ _hb_directwrite_shape(hb_shape_plan_t *shape_plan,
textString[chars_len++] = 0xFFFDu;
else {
textString[chars_len++] = 0xD800u + ((c - 0x10000u) >> 10);
textString[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1 << 10) - 1));
textString[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1u << 10) - 1));
}
}
......
......@@ -35,8 +35,6 @@
#include "hb-ot-head-table.hh"
#include "hb-ot-maxp-table.hh"
#include "hb-cache-private.hh"
#include <string.h>
......
......@@ -35,8 +35,6 @@
#include "hb-ot-head-table.hh"
#include "hb-ot-maxp-table.hh"
#include "hb-cache-private.hh"
#include <string.h>
......
......@@ -33,6 +33,8 @@
#include "hb-font-private.hh"
#include "hb-cache-private.hh" // Maybe use in the future?
#include FT_ADVANCES_H
#include FT_TRUETYPE_TABLES_H
......@@ -606,8 +608,8 @@ hb_ft_font_create (FT_Face ft_face,
hb_face_destroy (face);
_hb_ft_font_set_funcs (font, ft_face, false);
hb_font_set_scale (font,
(int) (((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM + (1<<15)) >> 16),
(int) (((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM + (1<<15)) >> 16));
(int) (((uint64_t) ft_face->size->metrics.x_scale * (uint64_t) ft_face->units_per_EM + (1u<<15)) >> 16),
(int) (((uint64_t) ft_face->size->metrics.y_scale * (uint64_t) ft_face->units_per_EM + (1u<<15)) >> 16));
#if 0 /* hb-ft works in no-hinting model */
hb_font_set_ppem (font,
ft_face->size->metrics.x_ppem,
......
......@@ -243,11 +243,11 @@ hb_ot_map_builder_t::compile (hb_ot_map_t &m)
map->mask = 1;
} else {
map->shift = next_bit;
map->mask = (1 << (next_bit + bits_needed)) - (1 << next_bit);
map->mask = (1u << (next_bit + bits_needed)) - (1u << next_bit);
next_bit += bits_needed;
m.global_mask |= (info->default_value << map->shift) & map->mask;
}
map->_1_mask = (1 << map->shift) & map->mask;
map->_1_mask = (1u << map->shift) & map->mask;
map->needs_fallback = !found;
}
......
......@@ -313,7 +313,7 @@ struct hb_set_t
for (unsigned int i = 0; i < ELTS; i++)
if (elts[i])
for (unsigned int j = 0; j < BITS; j++)
if (elts[i] & (1 << j))
if (elts[i] & (1u << j))
return i * BITS + j;
return INVALID;
}
......@@ -322,7 +322,7 @@ struct hb_set_t
for (unsigned int i = ELTS; i; i--)
if (elts[i - 1])
for (unsigned int j = BITS; j; j--)
if (elts[i - 1] & (1 << (j - 1)))
if (elts[i - 1] & (1u << (j - 1)))
return (i - 1) * BITS + (j - 1);
return INVALID;
}
......
......@@ -771,7 +771,7 @@ retry:
pchars[chars_len++] = 0xFFFDu;
else {
pchars[chars_len++] = 0xD800u + ((c - 0x10000u) >> 10);
pchars[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1 << 10) - 1));
pchars[chars_len++] = 0xDC00u + ((c - 0x10000u) & ((1u << 10) - 1));
}
}
......@@ -827,7 +827,7 @@ retry:
/* MinGW32 doesn't define fMergeNeutralItems, so we bruteforce */
//bidi_control.fMergeNeutralItems = true;
*(uint32_t*)&bidi_control |= 1<<24;
*(uint32_t*)&bidi_control |= 1u<<24;
bidi_state.uBidiLevel = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1;
bidi_state.fOverrideDirection = 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册