summaryrefslogtreecommitdiffstats
path: root/liblzma/simple
diff options
context:
space:
mode:
Diffstat (limited to 'liblzma/simple')
-rw-r--r--liblzma/simple/arm.c6
-rw-r--r--liblzma/simple/armthumb.c8
-rw-r--r--liblzma/simple/ia64.c2
-rw-r--r--liblzma/simple/powerpc.c9
-rw-r--r--liblzma/simple/simple_coder.c10
-rw-r--r--liblzma/simple/simple_decoder.c2
-rw-r--r--liblzma/simple/simple_encoder.c2
-rw-r--r--liblzma/simple/x86.c2
8 files changed, 25 insertions, 16 deletions
diff --git a/liblzma/simple/arm.c b/liblzma/simple/arm.c
index 181d0e3..ff5073a 100644
--- a/liblzma/simple/arm.c
+++ b/liblzma/simple/arm.c
@@ -22,9 +22,9 @@ arm_code(void *simple lzma_attribute((__unused__)),
size_t i;
for (i = 0; i + 4 <= size; i += 4) {
if (buffer[i + 3] == 0xEB) {
- uint32_t src = (buffer[i + 2] << 16)
- | (buffer[i + 1] << 8)
- | (buffer[i + 0]);
+ uint32_t src = ((uint32_t)(buffer[i + 2]) << 16)
+ | ((uint32_t)(buffer[i + 1]) << 8)
+ | (uint32_t)(buffer[i + 0]);
src <<= 2;
uint32_t dest;
diff --git a/liblzma/simple/armthumb.c b/liblzma/simple/armthumb.c
index eab4862..a8da334 100644
--- a/liblzma/simple/armthumb.c
+++ b/liblzma/simple/armthumb.c
@@ -23,10 +23,10 @@ armthumb_code(void *simple lzma_attribute((__unused__)),
for (i = 0; i + 4 <= size; i += 2) {
if ((buffer[i + 1] & 0xF8) == 0xF0
&& (buffer[i + 3] & 0xF8) == 0xF8) {
- uint32_t src = ((buffer[i + 1] & 0x7) << 19)
- | (buffer[i + 0] << 11)
- | ((buffer[i + 3] & 0x7) << 8)
- | (buffer[i + 2]);
+ uint32_t src = (((uint32_t)(buffer[i + 1]) & 7) << 19)
+ | ((uint32_t)(buffer[i + 0]) << 11)
+ | (((uint32_t)(buffer[i + 3]) & 7) << 8)
+ | (uint32_t)(buffer[i + 2]);
src <<= 1;
diff --git a/liblzma/simple/ia64.c b/liblzma/simple/ia64.c
index 580529e..6492d0a 100644
--- a/liblzma/simple/ia64.c
+++ b/liblzma/simple/ia64.c
@@ -70,7 +70,7 @@ ia64_code(void *simple lzma_attribute((__unused__)),
inst_norm |= (uint64_t)(dest & 0x100000)
<< (36 - 20);
- instruction &= (1 << bit_res) - 1;
+ instruction &= (1U << bit_res) - 1;
instruction |= (inst_norm << bit_res);
for (size_t j = 0; j < 6; j++)
diff --git a/liblzma/simple/powerpc.c b/liblzma/simple/powerpc.c
index 54dfbf1..0b60e9b 100644
--- a/liblzma/simple/powerpc.c
+++ b/liblzma/simple/powerpc.c
@@ -25,10 +25,11 @@ powerpc_code(void *simple lzma_attribute((__unused__)),
if ((buffer[i] >> 2) == 0x12
&& ((buffer[i + 3] & 3) == 1)) {
- const uint32_t src = ((buffer[i + 0] & 3) << 24)
- | (buffer[i + 1] << 16)
- | (buffer[i + 2] << 8)
- | (buffer[i + 3] & (~3));
+ const uint32_t src
+ = (((uint32_t)(buffer[i + 0]) & 3) << 24)
+ | ((uint32_t)(buffer[i + 1]) << 16)
+ | ((uint32_t)(buffer[i + 2]) << 8)
+ | ((uint32_t)(buffer[i + 3]) & ~UINT32_C(3));
uint32_t dest;
if (is_encoder)
diff --git a/liblzma/simple/simple_coder.c b/liblzma/simple/simple_coder.c
index 13ebabc..4f499be 100644
--- a/liblzma/simple/simple_coder.c
+++ b/liblzma/simple/simple_coder.c
@@ -118,7 +118,15 @@ simple_code(void *coder_ptr, const lzma_allocator *allocator,
// coder->pos and coder->size yet. This way the coder can be
// restarted if the next filter in the chain returns e.g.
// LZMA_MEM_ERROR.
- memcpy(out + *out_pos, coder->buffer + coder->pos, buf_avail);
+ //
+ // Do the memcpy() conditionally because out can be NULL
+ // (in which case buf_avail is always 0). Calling memcpy()
+ // with a null-pointer is undefined even if the third
+ // argument is 0.
+ if (buf_avail > 0)
+ memcpy(out + *out_pos, coder->buffer + coder->pos,
+ buf_avail);
+
*out_pos += buf_avail;
// Copy/Encode/Decode more data to out[].
diff --git a/liblzma/simple/simple_decoder.c b/liblzma/simple/simple_decoder.c
index 1d864f2..dc4d241 100644
--- a/liblzma/simple/simple_decoder.c
+++ b/liblzma/simple/simple_decoder.c
@@ -28,7 +28,7 @@ lzma_simple_props_decode(void **options, const lzma_allocator *allocator,
if (opt == NULL)
return LZMA_MEM_ERROR;
- opt->start_offset = unaligned_read32le(props);
+ opt->start_offset = read32le(props);
// Don't leave an options structure allocated if start_offset is zero.
if (opt->start_offset == 0)
diff --git a/liblzma/simple/simple_encoder.c b/liblzma/simple/simple_encoder.c
index 8aa463b..d2cc03e 100644
--- a/liblzma/simple/simple_encoder.c
+++ b/liblzma/simple/simple_encoder.c
@@ -32,7 +32,7 @@ lzma_simple_props_encode(const void *options, uint8_t *out)
if (opt == NULL || opt->start_offset == 0)
return LZMA_OK;
- unaligned_write32le(out, opt->start_offset);
+ write32le(out, opt->start_offset);
return LZMA_OK;
}
diff --git a/liblzma/simple/x86.c b/liblzma/simple/x86.c
index 0b14807..0e78909 100644
--- a/liblzma/simple/x86.c
+++ b/liblzma/simple/x86.c
@@ -97,7 +97,7 @@ x86_code(void *simple_ptr, uint32_t now_pos, bool is_encoder,
if (!Test86MSByte(b))
break;
- src = dest ^ ((1 << (32 - i * 8)) - 1);
+ src = dest ^ ((1U << (32 - i * 8)) - 1);
}
buffer[buffer_pos + 4]