[devel] [APT PATCH] rpmSingle{Pkg, Src}Index::ArchiveURI(): avoid cases with undefined behavior
Dmitry V. Levin
ldv на altlinux.org
Вс Фев 16 14:17:00 MSK 2020
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
Подробная информация о списке рассылки Devel