Skip to content

Commit dc505be

Browse files
marschapfrankmorgner
authored andcommitted
openpgp-tool: use binary OR for calculating 32-bit integers from byte
Also avoid potential unintended sign extension (SIGN_EXTENSION).
1 parent b11cc38 commit dc505be

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/tools/openpgp-tool.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static char *prettify_algorithm(u8 *data, size_t length)
239239
static char *prettify_date(u8 *data, size_t length)
240240
{
241241
if (data != NULL && length == 4) {
242-
time_t time = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
242+
time_t time = (time_t) (data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]);
243243
struct tm *tp;
244244
static char result[64]; /* large enough */
245245

@@ -312,9 +312,9 @@ static char *prettify_serialnumber(u8 *data, size_t length)
312312
{
313313
if (data != NULL && length >= 4) {
314314
static char result[15]; /* large enough for even 2*3 digits + separator */
315-
unsigned int serial = (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
315+
unsigned long serial = (unsigned long) (data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3]);
316316

317-
sprintf(result, "%08X", serial);
317+
sprintf(result, "%08lX", serial);
318318
return result;
319319
}
320320
return NULL;

0 commit comments

Comments
 (0)