From: Mathieu Desnoyers Date: Fri, 4 Sep 2015 05:43:31 +0000 (-0400) Subject: Cleanup: eliminate implicit sign-extension X-Git-Url: http://git.efficios.com/?p=deliverable%2Flttng-ust.git;a=commitdiff_plain;h=4c5dac0d3db2e2e6daef2f5e137abc2e93ed0302 Cleanup: eliminate implicit sign-extension Coverity reported: CID 1321723 (#1 of 1): Unintended sign extension (SIGN_EXTENSION)sign_extension: Suspicious implicit sign extension: elf->ehdr->e_shentsize with type unsigned short (16 bits, unsigned) is promoted in index * elf->ehdr->e_shentsize to type int (32 bits, signed), then sign-extended to type unsigned long (64 bits, unsigned). If index * elf->ehdr->e_shentsize is greater than 0x7FFFFFFF, the upper bits of the result will all be 1. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttng-ust/lttng-ust-elf.c b/liblttng-ust/lttng-ust-elf.c index dd50f2b6..8d3fc573 100644 --- a/liblttng-ust/lttng-ust-elf.c +++ b/liblttng-ust/lttng-ust-elf.c @@ -101,7 +101,7 @@ struct lttng_ust_elf_shdr *lttng_ust_elf_get_shdr(struct lttng_ust_elf *elf, uint16_t index) { struct lttng_ust_elf_shdr *shdr = NULL; - long offset; + off_t offset; if (!elf) { goto error; @@ -116,7 +116,8 @@ struct lttng_ust_elf_shdr *lttng_ust_elf_get_shdr(struct lttng_ust_elf *elf, goto error; } - offset = elf->ehdr->e_shoff + index * elf->ehdr->e_shentsize; + offset = (off_t) elf->ehdr->e_shoff + + (off_t) index * elf->ehdr->e_shentsize; if (lseek(elf->fd, offset, SEEK_SET) < 0) { goto error; }