htons() returns wrong type on non-{i386,amd64} platforms
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
eglibc |
Fix Released
|
Medium
|
|||
eglibc (Ubuntu) |
Fix Released
|
Undecided
|
Unassigned | ||
Precise |
Fix Released
|
Medium
|
Adam Conrad | ||
glibc (Fedora) |
Fix Released
|
Medium
|
Bug Description
[Impact]
htons() on non x86 platforms is missing a cast to uint16_t which causes FTBFS of mosh on armel and armhf.
[Development Fix]
This has been fixed in eglibc in Quantal.
[Stable Fix]
A fix can be backported from the Quantal development version into Precise.
[Test Case]
See https:/
On how to reproduce with a C program.
[Regression Potential]
This patch affects some of the generic byteswaping code in eglibc. The fix for x86 arches was already completed years ago, and this patch fixes is for other arches.
--
The definition of htons() on platforms other than i386 and amd64 is missing a cast to uint16_t, which caused this FTBFS of mosh on armel and armhf:
https:/
network.cc:76:28: error: narrowing conversion of '({...})' from 'unsigned int' to 'uint16_t {aka short unsigned int}' inside { } is ill-formed in C++11 [-Werror=narrowing]
network.cc:76:50: error: narrowing conversion of '({...})' from 'unsigned int' to 'uint16_t {aka short unsigned int}' inside { } is ill-formed in C++11 [-Werror=narrowing]
(We didn’t see this before because this warning is new in GCC 4.7.)
This was fixed for glibc 2.16 in
http://
Changed in eglibc: | |
importance: | Unknown → Medium |
status: | Unknown → Fix Released |
description: | updated |
Changed in eglibc (Ubuntu Precise): | |
assignee: | nobody → Adam Conrad (adconrad) |
importance: | Undecided → Medium |
status: | New → In Progress |
Changed in glibc (Fedora): | |
importance: | Unknown → Medium |
status: | Unknown → Fix Released |
The following (legitimate) code will generate a warning when both -O2 and
-Wconversion is enabled but not when only -Wconversion is enabled.
Code:
#include <arpa/inet.h>
// Nonsense code to illustrate problem
int main(void) {
uint16_t portnbr=0;
uint16_t n_portnbr = htons(portnbr);
exit(0);
}
With optimization
$> gcc -std=gnu99 -Wconversion -Werror -O2 -c tsthtons.c
cc1: warnings being treated as errors
tsthtons.c: In function ‘main’:
tsthtons.c:6: error: conversion to ‘short unsigned int’ from ‘int’ may alter its value
and without
$>gcc -std=gnu99 -Wconversion -Werror -c tsthtons.c
$>
in both cases
gcc --version
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]
Copyright (C) 2009 Free Software Foundation, Inc.
and gnu clib v2.10.1