[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#259318: marked as done (pass by reference broken)



Your message dated Wed, 14 Jul 2004 08:44:17 +0200
with message-id <87brijdr5q.fsf@informatik.uni-tuebingen.de>
and subject line Bug#259318: pass by reference broken
has caused the attached Bug report to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what I am
talking about this indicates a serious mail system misconfiguration
somewhere.  Please contact me immediately.)

Debian bug tracking system administrator
(administrator, Debian Bugs database)

--------------------------------------
Received: (at submit) by bugs.debian.org; 14 Jul 2004 00:06:30 +0000
>From abgrover@cc.usu.edu Tue Jul 13 17:06:30 2004
Return-path: <abgrover@cc.usu.edu>
Received: from ms2.usu.edu [129.123.104.12] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1BkXI6-0004Mc-00; Tue, 13 Jul 2004 17:06:30 -0700
Received: from webster.usu.edu (webster.usu.edu [129.123.1.90])
	by ms2.usu.edu (8.12.10/8.12.10) with ESMTP id i6E05wQL011323
	for <submit@bugs.debian.org>; Tue, 13 Jul 2004 18:05:58 -0600
X-WebMail-UserID: abgrover
Date: Tue, 13 Jul 2004 18:05:58 -0600
Sender: Alan <abgrover@cc.usu.edu>
From: Alan <abgrover@cc.usu.edu>
To: submit <submit@bugs.debian.org>
X-EXP32-SerialNo: 00002751
Subject: pass by reference broken
Message-ID: <[🔎] 40F47CB0@webster.usu.edu>
Mime-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 7bit
X-Mailer: WebMail (Hydra) SMTP v3.62
X-USU-MailScanner-Information: Please contact the ISP for more information
X-USU-MailScanner: Found to be clean
X-MailScanner-From: abgrover@cc.usu.edu
Delivered-To: submit@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-6.0 required=4.0 tests=BAYES_20,HAS_PACKAGE 
	autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

Package: g++-3.3
Version: 1:3.3.4-2

Pass by reference seems to be broken in g++.

Originally I thought the problem might be in ntohl, which is why it
appears in the test below.  However, the real problem seems to be in the
  mechanics of passing data.  A different variant of the program below
showed no problems in ntohl.  I also considered casting as the source of
the problem, but that also seems to work fine.

The program below gave the following output when compiled with g++-3.3
3.3.4 (Debian 1:3.3.4-2) :

alan@1[alan]$ ./testp
cast test: tmp is 4294967295, result is -1
ntohl test: result is -1

And the following correct output when compiled with g++-3.2 3.2.3 (Debian):

alan@1[alan]$ ./testp
cast test: tmp is 4294967295, result is -1
ntohl test: result is -6

This seems to show that result might have been passed by value instead
of by reference, since the value of result does not change.

Here is the test program:


// ------------begin test program---------------
#include <stdio.h>
#include <netinet/in.h>
#include <stdint.h>

uint32_t Read (uint32_t& v, char * buf);

int32_t Read (int32_t& v, char * buf);


int
main()
{
	char buffer[] = {
		255, 255, 255, 250  // -6 in network byte order
	};

	int32_t result = -1;
	uint32_t tmp = static_cast<uint32_t>(result);
	result = static_cast<int32_t>(tmp);

	printf("cast test: tmp is %u, result is %d\n", tmp, result);

	Read(result, buffer);
	printf("ntohl test: result is %d\n", result);
	return 0;
}


int32_t
Read(int32_t& v, char * buf)
{
	Read(static_cast<uint32_t>(v), buf);
	return v;
}

uint32_t
Read(uint32_t& v, char * buf)
{

	v = ntohl(*(reinterpret_cast<uint32_t*>(buf)));
	return v;

}
//------------end test program------------------------------


---------------------------------------
Received: (at 259318-done) by bugs.debian.org; 14 Jul 2004 07:08:40 +0000
>From hueffner@informatik.uni-tuebingen.de Wed Jul 14 00:08:40 2004
Return-path: <hueffner@informatik.uni-tuebingen.de>
Received: from mx5.informatik.uni-tuebingen.de [134.2.12.32] 
	by spohr.debian.org with esmtp (Exim 3.35 1 (Debian))
	id 1Bkdse-0005a9-00; Wed, 14 Jul 2004 00:08:40 -0700
Received: from localhost (loopback [127.0.0.1])
	by mx5.informatik.uni-tuebingen.de (Postfix) with ESMTP id 04AF62A9
	for <259318-done@bugs.debian.org>; Wed, 14 Jul 2004 09:08:08 +0200 (MST)
Received: from mx3.informatik.uni-tuebingen.de ([134.2.12.26])
 by localhost (mx5 [134.2.12.32]) (amavisd-new, port 10024) with ESMTP
 id 36818-03 for <259318-done@bugs.debian.org>;
 Wed, 14 Jul 2004 09:08:06 +0200 (DFT)
Received: from juist (semeai.Informatik.Uni-Tuebingen.De [134.2.15.66])
	by mx3.informatik.uni-tuebingen.de (Postfix) with ESMTP id 434BA14B
	for <259318-done@bugs.debian.org>; Wed, 14 Jul 2004 09:08:06 +0200 (DFT)
Received: from falk by juist with local (Exim 3.36 #1 (Debian))
	id 1BkdV3-00058B-00
	for <259318-done@bugs.debian.org>; Wed, 14 Jul 2004 08:44:17 +0200
To: 259318-done@bugs.debian.org
Subject: Re: Bug#259318: pass by reference broken
References: <[🔎] 40F47CB0@webster.usu.edu>
From: Falk Hueffner <hueffner@informatik.uni-tuebingen.de>
X-Face: "iUeUu$b*W_"w?tV83Y3*r:`rh&dRv}$YnZ3,LVeCZSYVuf[Gpo*5%_=/\_!gc_,SS}[~xZ
 wY77I-M)xHIx:2f56g%/`SOw"Dx%4Xq0&f\Tj~>|QR|vGlU}TBYhiG(K:2<T^
Date: Wed, 14 Jul 2004 08:44:17 +0200
In-Reply-To: <[🔎] 40F47CB0@webster.usu.edu> (Alan's message of "Tue, 13 Jul 2004
 18:05:58 -0600")
Message-ID: <87brijdr5q.fsf@informatik.uni-tuebingen.de>
User-Agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.5 (cabbage, linux)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Virus-Scanned: by amavisd-new (McAfee AntiVirus) at informatik.uni-tuebingen.de
Delivered-To: 259318-done@bugs.debian.org
X-Spam-Checker-Version: SpamAssassin 2.60-bugs.debian.org_2004_03_25 
	(1.212-2003-09-23-exp) on spohr.debian.org
X-Spam-Status: No, hits=-6.0 required=4.0 tests=BAYES_00,HAS_BUG_NUMBER 
	autolearn=no version=2.60-bugs.debian.org_2004_03_25
X-Spam-Level: 

Alan <abgrover@cc.usu.edu> writes:

> uint32_t Read (uint32_t& v, char * buf);
>
>
> 	Read(static_cast<uint32_t>(v), buf);

Initialization of a non-const reference from a temporary is invalid.
Newer g++ will even diagnose this and error out.

-- 
	Falk



Reply to: