diff options
author | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-03-05 09:10:55 +0000 |
---|---|---|
committer | Akira Kakuto <kakuto@fuk.kindai.ac.jp> | 2018-03-05 09:10:55 +0000 |
commit | cc577ce8c5e051967fce0ae954f78874e400c2f8 (patch) | |
tree | 9b1d8e3144cb7f49ffe2c1eb1ec189b6c04ba174 /Build/source/libs/graphite2/graphite2-src/src/inc | |
parent | 0ab585a159d6f011c3eb364d7c0dc20424ef0738 (diff) |
graphite2-1.3.11
git-svn-id: svn://tug.org/texlive/trunk@46828 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/graphite2/graphite2-src/src/inc')
12 files changed, 103 insertions, 49 deletions
diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h index 3985ae416e9..3439299e3d6 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Code.h @@ -162,7 +162,7 @@ inline void Machine::Code::externalProgramMoved(ptrdiff_t dist) throw() { if (_code && !_own) { - _code += dist / sizeof(instr); + _code += dist / signed(sizeof(instr)); _data += dist; } } diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h index 5d953b4a4cb..267776dd4e9 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Collider.h @@ -210,6 +210,7 @@ private: float _sliceWidth; // width of each slice float _mingap; float _xbound; // max or min edge + bool _hit; #if !defined GRAPHITE2_NTRACING // Debugging @@ -233,7 +234,8 @@ KernCollider::KernCollider(GR_MAYBE_UNUSED json *dbg) _maxy(1e38f), _sliceWidth(0.0f), _mingap(0.0f), - _xbound(0.0) + _xbound(0.0), + _hit(false) { #if !defined GRAPHITE2_NTRACING _seg = 0; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h index 61351c416ea..6596af2ffa4 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Compression.h @@ -47,7 +47,10 @@ typedef uint32_t u32; typedef uint64_t u64; #endif -ptrdiff_t const MINMATCH = 4; +ptrdiff_t const MINMATCH = 4, + LASTLITERALS = 5, + MINCODA = LASTLITERALS+1, + MINSRCSIZE = 13; template<int S> inline diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h b/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h index fc845f6e165..9610c39a487 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/FeatureMap.h @@ -56,7 +56,6 @@ class FeatureRef static const uint8 SIZEOF_CHUNK = sizeof(chunk_t)*8; public: - FeatureRef(); FeatureRef(const Face & face, unsigned short & bits_offset, uint32 max_val, uint32 name, uint16 uiName, uint16 flags, FeatureSetting *settings, uint16 num_set) throw(); @@ -76,14 +75,14 @@ public: uint16 getSettingName(uint16 index) const { return m_nameValues[index].label(); } int16 getSettingValue(uint16 index) const { return m_nameValues[index].value(); } uint32 maxVal() const { return m_max; } - const Face* getFace() const { return m_pFace;} + const Face & getFace() const { return m_face;} const FeatureMap* getFeatureMap() const;// { return m_pFace;} CLASS_NEW_DELETE; private: FeatureRef(const FeatureRef & rhs); - const Face * m_pFace; //not NULL + const Face & m_face; FeatureSetting * m_nameValues; // array of name table ids for feature values chunk_t m_mask, // bit mask to get the value from the vector m_max; // max value the value can take @@ -99,27 +98,18 @@ private: //unimplemented }; -inline -FeatureRef::FeatureRef() -: m_pFace(0), m_nameValues(0), - m_mask(0), m_max(0), m_id(0), - m_nameid(0), m_flags(0), m_numSet(0), - m_bits(0), m_index(0) -{ -} - class NameAndFeatureRef { public: NameAndFeatureRef(uint32 name = 0) : m_name(name) , m_pFRef(NULL){} - NameAndFeatureRef(const FeatureRef* p/*not NULL*/) : m_name(p->getId()), m_pFRef(p) {} + NameAndFeatureRef(FeatureRef const & p) : m_name(p.getId()), m_pFRef(&p) {} bool operator<(const NameAndFeatureRef& rhs) const //orders by m_name { return m_name<rhs.m_name; } CLASS_NEW_DELETE - + uint32 m_name; const FeatureRef* m_pFRef; }; @@ -128,7 +118,7 @@ class FeatureMap { public: FeatureMap() : m_numFeats(0), m_feats(NULL), m_pNamedFeats(NULL) {} - ~FeatureMap() { delete [] m_feats; delete[] m_pNamedFeats; } + ~FeatureMap() { free(m_feats); delete[] m_pNamedFeats; } bool readFeats(const Face & face); const FeatureRef *findFeatureRef(uint32 name) const; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Font.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Font.h index bc7084050e5..df6e79b61a3 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Font.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Font.h @@ -44,6 +44,7 @@ public: float scale() const; bool isHinted() const; const Face & face() const; + operator bool () const throw() { return m_advances; } CLASS_NEW_DELETE; private: diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/List.h b/Build/source/libs/graphite2/graphite2-src/src/inc/List.h index 020560235c1..eacb1cfd5cb 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/List.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/List.h @@ -34,6 +34,7 @@ of the License or (at your option) any later version. #include <cstdlib> #include <new> +#include "Main.h" namespace graphite2 { @@ -104,7 +105,9 @@ void Vector<T>::reserve(size_t n) if (n > capacity()) { const ptrdiff_t sz = size(); - m_first = static_cast<T*>(realloc(m_first, n*sizeof(T))); + size_t requested; + if (checked_mul(n,sizeof(T), requested)) std::abort(); + m_first = static_cast<T*>(realloc(m_first, requested)); if (!m_first) std::abort(); m_last = m_first + sz; m_end = m_first + n; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h index 1a01b7a43f7..b23819fb981 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Machine.h @@ -15,8 +15,8 @@ You should also have received a copy of the GNU Lesser General Public License along with this library in the file named "LICENSE". - If not, write to the Free Software Foundation, 51 Franklin Street, - Suite 500, Boston, MA 02110-1335, USA or visit their web page on the + If not, write to the Free Software Foundation, 51 Franklin Street, + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the internet at http://www.fsf.org/licenses/lgpl.html. Alternatively, the contents of this file may be used under the terms of the @@ -27,11 +27,12 @@ of the License or (at your option) any later version. // This general interpreter interface. // Author: Tim Eves -// Build one of direct_machine.cpp or call_machine.cpp to implement this +// Build one of direct_machine.cpp or call_machine.cpp to implement this // interface. #pragma once #include <cstring> +#include <limits> #include <graphite2/Types.h> #include "inc/Main.h" @@ -56,6 +57,13 @@ of the License or (at your option) any later version. #define REGPARM(n) #endif +#if defined(__MINGW32__) +// MinGW's <limits> at some point includes winnt.h which #define's a +// DELETE macro, which conflicts with enum opcode below, so we undefine +// it here. +#undef DELETE +#endif + namespace graphite2 { // Forward declarations @@ -64,7 +72,7 @@ class Slot; class SlotMap; -namespace vm +namespace vm { @@ -112,12 +120,12 @@ enum opcode { PUT_GLYPH, PUSH_GLYPH_ATTR, PUSH_ATT_TO_GLYPH_ATTR, BITOR, BITAND, BITNOT, BITSET, SET_FEAT, - MAX_OPCODE, + MAX_OPCODE, // private opcodes for internal use only, comes after all other on disk opcodes TEMP_COPY = MAX_OPCODE }; -struct opcode_t +struct opcode_t { instr impl[2]; uint8 param_sz; @@ -186,6 +194,8 @@ inline Machine::status_t Machine::status() const throw() inline void Machine::check_final_stack(const stack_t * const sp) { + if (_status != finished) return; + stack_t const * const base = _stack + STACK_GUARD, * const limit = base + STACK_MAX; if (sp < base) _status = stack_underflow; // This should be impossible now. @@ -195,6 +205,3 @@ inline void Machine::check_final_stack(const stack_t * const sp) } // namespace vm } // namespace graphite2 - - - diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h index deeffcccd5a..f66b48d0b7d 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Main.h @@ -15,8 +15,8 @@ You should also have received a copy of the GNU Lesser General Public License along with this library in the file named "LICENSE". - If not, write to the Free Software Foundation, 51 Franklin Street, - Suite 500, Boston, MA 02110-1335, USA or visit their web page on the + If not, write to the Free Software Foundation, 51 Franklin Street, + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the internet at http://www.fsf.org/licenses/lgpl.html. Alternatively, the contents of this file may be used under the terms of the @@ -77,15 +77,61 @@ public: struct telemetry {}; #endif +// Checked multiplaction to catch overflow or underflow when allocating memory +#if defined(__has_builtin) + #if __has_builtin(__builtin_mul_overflow) + #define HAVE_BUILTIN_OVERFLOW + #endif +#elif defined(__GNUC__) && (__GNUC__ >= 5) && !defined(__INTEL_COMPILER) + #define HAVE_BUILTIN_OVERFLOW +#endif +#if defined(__has_include) + #if __has_include(<intsafe.h>) + #define HAVE_INTSAFE_H + #endif +#elif defined(_WIN32) + #define HAVE_INTSAFE_H +#endif + +// Need to import intsafe into the top level namespace +#if defined(HAVE_INTSAFE_H) +} // namespace graphite2 + +#include <intsafe.h> + +namespace graphite2 { +#endif + +#if defined(HAVE_BUILTIN_OVERFLOW) +inline +bool checked_mul(const size_t a, const size_t b, size_t & t) { + return __builtin_mul_overflow(a, b, &t); +} +#elif defined(HAVE_INTSAFE_H) +inline +bool checked_mul(const size_t a, const size_t b, size_t & t) { + return SizeTMult(a, b, &t) == INTSAFE_E_ARITHMETIC_OVERFLOW; +} +#else +inline +bool checked_mul(const size_t a, const size_t b, size_t & t) { + t = a*b; + return (((a | b) & (~size_t(0) << (sizeof(size_t) << 2))) && (t / a != b)); +} +#endif + // typesafe wrapper around malloc for simple types // use free(pointer) to deallocate template <typename T> T * gralloc(size_t n) { + size_t total; + if (checked_mul(n, sizeof(T), total)) + return 0; #ifdef GRAPHITE2_TELEMETRY - telemetry::count_bytes(sizeof(T) * n); + telemetry::count_bytes(total); #endif - return static_cast<T*>(malloc(sizeof(T) * n)); + return static_cast<T*>(malloc(total)); } template <typename T> T * grzeroalloc(size_t n) @@ -128,7 +174,7 @@ inline T max(const T a, const T b) #if defined(__clang__) && __cplusplus >= 201103L /* clang's fallthrough annotations are only available starting in C++11. */ - #define GR_FALLTHROUGH [[clang::fallthrough]] + #define GR_FALLTHROUGH [[fallthrough]] #elif defined(_MSC_VER) /* * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis): @@ -136,6 +182,8 @@ inline T max(const T a, const T b) */ #include <sal.h> #define GR_FALLTHROUGH __fallthrough +#elif __GNUC__ >= 7 + #define GR_FALLTHROUGH __attribute__ ((fallthrough)) #else #define GR_FALLTHROUGH /* fallthrough */ #endif diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h index bcba1f2a87b..e5a8ad408a7 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Segment.h @@ -205,7 +205,7 @@ int8 Segment::getSlotBidiClass(Slot *s) const inline void Segment::finalise(const Font *font, bool reverse) { - if (!m_first) return; + if (!m_first || !m_last) return; m_advance = positionSlots(font, m_first, m_last, m_silf->dir(), true); //associateChars(0, m_numCharinfo); diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h b/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h index 4a8e3fa7d1f..ceb9cea6f39 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/Sparse.h @@ -15,8 +15,8 @@ You should also have received a copy of the GNU Lesser General Public License along with this library in the file named "LICENSE". - If not, write to the Free Software Foundation, 51 Franklin Street, - Suite 500, Boston, MA 02110-1335, USA or visit their web page on the + If not, write to the Free Software Foundation, 51 Franklin Street, + Suite 500, Boston, MA 02110-1335, USA or visit their web page on the internet at http://www.fsf.org/licenses/lgpl.html. Alternatively, the contents of this file may be used under the terms of the @@ -73,7 +73,7 @@ public: size_t size() const throw(); size_t _sizeof() const throw(); - + CLASS_NEW_DELETE; private: @@ -122,10 +122,7 @@ sparse::sparse(I attr, const I last) + n_values); if (m_array.values == 0) - { - free(m_array.values); m_array.map=0; return; - } // coverity[forward_null : FALSE] Since m_array is union and m_array.values is not NULL chunk * ci = m_array.map; diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h b/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h index 50ae1d4d077..0191088b220 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/opcode_table.h @@ -73,7 +73,7 @@ static const opcode_t opcode_table[] = {{do2(gtr_eq)}, 0, "GTR_EQ"}, // 0x18 {{do_(next), NILOP}, 0, "NEXT"}, - {{do_(next_n), NILOP}, 1, "NEXT_N"}, // number <= smap.end - map + {{NILOP, NILOP}, 1, "NEXT_N"}, // number <= smap.end - map {{do_(next), NILOP}, 0, "COPY_NEXT"}, {{do_(put_glyph_8bit_obs), NILOP}, 1, "PUT_GLYPH_8BIT_OBS"}, // output_class {{do_(put_subs_8bit_obs), NILOP}, 3, "PUT_SUBS_8BIT_OBS"}, // slot input_class output_class diff --git a/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h b/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h index 3b6dd3fc3d8..0064a3e678f 100644 --- a/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h +++ b/Build/source/libs/graphite2/graphite2-src/src/inc/opcodes.h @@ -26,7 +26,7 @@ of the License or (at your option) any later version. */ #pragma once // This file will be pulled into and integrated into a machine implmentation -// DO NOT build directly and under no circumstances every #include headers in +// DO NOT build directly and under no circumstances ever #include headers in // here or you will break the direct_machine. // // Implementers' notes @@ -65,7 +65,7 @@ of the License or (at your option) any later version. // #define NOT_IMPLEMENTED assert(false) -#define NOT_IMPLEMENTED +// #define NOT_IMPLEMENTED #define binop(op) const uint32 a = pop(); *sp = uint32(*sp) op a #define sbinop(op) const int32 a = pop(); *sp = int32(*sp) op a @@ -130,8 +130,10 @@ STARTOP(mul) ENDOP STARTOP(div_) - if (*sp == 0) DIE; - sbinop(/); + const int32 b = pop(); + const int32 a = int32(*sp); + if (b == 0 || (a == std::numeric_limits<int32>::min() && b == -1)) DIE; + *sp = int32(*sp) / b; ENDOP STARTOP(min_) @@ -208,12 +210,12 @@ STARTOP(next) ++map; ENDOP -STARTOP(next_n) - use_params(1); - NOT_IMPLEMENTED; +//STARTOP(next_n) +// use_params(1); +// NOT_IMPLEMENTED; //declare_params(1); //const size_t num = uint8(*param); -ENDOP +//ENDOP //STARTOP(copy_next) // if (is) is = is->next(); @@ -337,6 +339,7 @@ STARTOP(delete_) else seg.last(is->prev()); + if (is == smap.highwater()) smap.highwater(is->next()); if (is->prev()) |