From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Sun, 16 Feb 2020 14:17:00 +0300 From: "Dmitry V. Levin" To: Ivan Zakharyaschev Message-ID: <20200216111659.GA26792@altlinux.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Cc: darktemplar@altlinux.org, devel@lists.altlinux.org Subject: Re: [devel] [APT PATCH] rpmSingle{Pkg, Src}Index::ArchiveURI(): avoid cases with undefined behavior X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 16 Feb 2020 11:17:00 -0000 Archived-At: List-Archive: List-Post: On Sun, Feb 16, 2020 at 04:09:14AM +0300, Ivan Zakharyaschev wrote: > Two cases of UB are avoided with such a rewrite: > > * getcwd(2) returned NULL. Constructing a string from NULL is UB. > (Such string was passed as an argument to flCombine().) > Now, SafeGetCwd() (in fileutl.cc) returns "/" in such cases; > if you consider SafeGetCwd()'s implementation not to be reasonable, > rewrite it (just at a single place). ack > * File.length() < 2. Since File was a non-const string, > File[File.length()] might be UB before C++11. Now, File is const, and > it is guaranteed that File[File.length()] == 0. We can safely assume C++11, but I don't think we have an UB here even before C++11. Anyway, this part of the change is better covered by "Avoid copying objects" patch. -- ldv