diff options
| author | Nicolas Dufour <nicoduf@yahoo.fr> | 2015-03-31 10:33:40 +0000 |
|---|---|---|
| committer | JazzyNico <nicoduf@yahoo.fr> | 2015-03-31 10:33:40 +0000 |
| commit | 3c458ee86d50bf9e877b62ea5e30ba6d4b09bdae (patch) | |
| tree | 595cdcde1c625895d649314e05a21a098af33559 /src/trace/potrace/bitops.h | |
| parent | Add clipping at miter-length to 'arcs' line join. (diff) | |
| download | inkscape-3c458ee86d50bf9e877b62ea5e30ba6d4b09bdae.tar.gz inkscape-3c458ee86d50bf9e877b62ea5e30ba6d4b09bdae.zip | |
Updating Potrace from 1.10 to 1.12, fixing Bug #1438366 (CVE-2013-7437 vulnerability).
Fixed bugs:
- https://launchpad.net/bugs/1438366
(bzr r14037)
Diffstat (limited to 'src/trace/potrace/bitops.h')
| -rw-r--r-- | src/trace/potrace/bitops.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/trace/potrace/bitops.h b/src/trace/potrace/bitops.h new file mode 100644 index 000000000..cff734a46 --- /dev/null +++ b/src/trace/potrace/bitops.h @@ -0,0 +1,83 @@ +/* Copyright (C) 2001-2015 Peter Selinger. + This file is part of Potrace. It is free software and it is covered + by the GNU General Public License. See the file COPYING for details. */ + + +/* bits.h: this file defines some macros for bit manipulations. We + provide a generic implementation, as well as machine- and + compiler-specific fast implementations */ + +/* lobit: return the position of the rightmost "1" bit of an int, or + 32 if none. hibit: return 1 + the position of the leftmost "1" bit + of an int, or 0 if none. Note: these functions work on 32-bit + integers. */ + +#ifndef BITOPS_H +#define BITOPS_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/* ---------------------------------------------------------------------- */ +/* machine specific macros */ + +#if defined(HAVE_I386) + +static inline unsigned int lobit(unsigned int x) { + unsigned int res; + asm ("bsf %1,%0\n\t" + "jnz 0f\n\t" + "movl $32,%0\n" + "0:" + : "=r" (res) + : "r" (x) + : "cc"); + return res; +} + +static inline unsigned int hibit(unsigned int x) { + unsigned int res; + + asm ("bsr %1,%0\n\t" + "jnz 0f\n\t" + "movl $-1,%0\n" + "0:" + : "=r" (res) + : "r" (x) + : "cc"); + return res+1; +} + +/* ---------------------------------------------------------------------- */ +#else /* generic macros */ + +static inline unsigned int lobit(unsigned int x) { + unsigned int res = 32; + while (x & 0xffffff) { + x <<= 8; + res -= 8; + } + while (x) { + x <<= 1; + res -= 1; + } + return res; +} + +static inline unsigned int hibit(unsigned int x) { + unsigned int res = 0; + while (x > 0xff) { + x >>= 8; + res += 8; + } + while (x) { + x >>= 1; + res += 1; + } + return res; +} + +#endif + +#endif /* BITOPS_H */ |
