From 05b1c13e36ec49891e89593b25e668e983a4fc41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20H=C3=B6gberg?= Date: Tue, 24 Apr 2018 13:30:00 +0200 Subject: heart: Use ntohs instead of manual conversion Multiplying a signed char by 256 is undefined behavior and caused problems on some platforms when the length was long enough. We could cast it to an unsigned int to make it work, but it's best not to reinvent the wheel. Fixes OTP-15034 --- erts/etc/common/heart.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'erts/etc/common') diff --git a/erts/etc/common/heart.c b/erts/etc/common/heart.c index 01ef840b5d..aaaffbca79 100644 --- a/erts/etc/common/heart.c +++ b/erts/etc/common/heart.c @@ -847,11 +847,8 @@ write_message(fd, mp) int fd; struct msg *mp; { - int len; - char* tmp; + int len = ntohs(mp->len); - tmp = (char*) &(mp->len); - len = (*tmp * 256) + *(tmp+1); if ((len == 0) || (len > MSG_BODY_SIZE)) { return MSG_HDR_SIZE; } /* cc68k wants (char *) */ -- cgit v1.2.3