This is the mail archive of the mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] setup.exe: Use String object to hold the exception descriptionin an Exception object.


This patch was inspired by a bug present in the CVS version of setup.exe.

In the current code an exception of type class Exception is thrown like 

  throw new Exception ("__LINE__ __FILE__",

What is wrong here is using String::cstr_oneuse() to get the exception 
description. When an exception thrown this way is catched at some point, 
it is highly unlikely that the description will be valid anymore. The 
current way that the description is constructed, using temporary string 
objects, ensures that the description will never be valid when the 
exception is caught.

My fix uses a String object to hold the description in the Exception 
object. Additionally it adds  a second constructor to the Exception class, 
which takes a object of type String as the second argument. I did this 
change, hoping that this will make the code slightly faster and not so 
"ugly".  So now you construct an Exception object like this:

  new Exception ("__LINE__ __FILE__", String ("something"), 

The new constructor uses operator = of the String class which is faster 
than the constructor taking String&.

Here is Changelog entry:

2003-02-16  Pavel Tsekov  <>

	* Exception.h: Declare new constructor.
	(Exception::_message): Change the type from 'const char *' to
	'class String'.
	(Exception::~Exception): Implement destructor (make gcc shut up).
	* Implement new constructor.
	(Exception::what): Use String::cstr_oneuse ().
	* (validateCachedPackage): Use the constructor, which
	takes String& as its second argument, when throwing objects
	of type Exception.
	(check_for_cached): Ditto.
	* (install_one_source): Ditto.

P.S. To reproduce the bug, use custom mirror, which has a setup.ini 
file with invalid md5 checksums for binary packages, and try to install
a package from it. You can use -
I've put a broken setup.ini file there. Try to install the 
package nfs-server 2.2.47-4.

Attachment: setup-exception.c.diff
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]