From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Mon, 9 Dec 2019 02:21:08 +0300 From: "Dmitry V. Levin" To: Aleksei Nikiforov Message-ID: <20191208232108.GC30742@altlinux.org> References: <20191206133647.dculnmwkd3yf2wjp@titan.localdomain> <20191206153655.86334-1-darktemplar@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="2/5bycvrmDh4d1IB" Content-Disposition: inline In-Reply-To: <20191206153655.86334-1-darktemplar@altlinux.org> Cc: ALT Devel discussion list Subject: Re: [devel] [PATCH for apt 2/2 v2] Fix pointer arithmetics 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, 08 Dec 2019 23:21:08 -0000 Archived-At: List-Archive: List-Post: --2/5bycvrmDh4d1IB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Dec 06, 2019 at 06:36:55PM +0300, Aleksei Nikiforov wrote: [...] > @@ -85,11 +87,11 @@ class pkgCache::PkgIterator > inline unsigned long long Index() const {return Pkg - Owner->PkgP;}; > OkState State() const; > =20 > - void ReMap(void const * const oldMap, void const * const newMap) > + void ReMap(void *oldMap, void *newMap) Is there any particular reason for stripping const here and in other similar places? [...] > @@ -301,7 +302,7 @@ std::experimental::optional DynamicMMap::= Allocate(unsigned long Item > Pool* oldPools =3D Pools; > auto idxResult =3D RawAllocate(I->Count*ItemSize,ItemSize); > if (Pools !=3D oldPools) > - I +=3D Pools - oldPools; > + I =3D RebasePointer(I, oldPools, Pools); > =20 > // Does the allocation failed ? > if (!idxResult) In my patch RebasePointer invocation was after the idxResult check, not before the check. By the way, in this and other similar cases, is there any reason for "Pools !=3D oldPools" check? Is RebasePointer incapable of handling this, or is it an optimization? [...] > diff --git a/apt/apt-pkg/rebase_pointer.h b/apt/apt-pkg/rebase_pointer.h > new file mode 100644 > index 0000000..f6b3c15 > --- /dev/null > +++ b/apt/apt-pkg/rebase_pointer.h > @@ -0,0 +1,16 @@ > +#ifndef PKGLIB_REBASE_POINTER_H > +#define PKGLIB_REBASE_POINTER_H > + > +template > +static inline T* RebasePointer(T *ptr, void *old_base, void *new_base) > +{ > + return reinterpret_cast(reinterpret_cast(new_base) + (rein= terpret_cast(ptr) - reinterpret_cast(old_base))); > +} > + > +template > +static inline const T* RebasePointer(const T *ptr, void *old_base, void = *new_base) > +{ > + return reinterpret_cast(reinterpret_cast(new_base) += (reinterpret_cast(ptr) - reinterpret_cast(old_base))); > +} > + > +#endif Do we really need two templates here? --=20 ldv --2/5bycvrmDh4d1IB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJd7YVkAAoJEAVFT+BVnCUIQJ0QANQ9DJxzmR4aSbqKmWBByIfq wJDrDMx6Js6fKmHBSuMvPTCEdPBnaNhCWwo9HQQ0H5UOsJE23AG2ot8Ml7EjCFfZ NEJbzaRtCNq2YFVRWXCLyzmhEZn7HWXjRxeI536RGPOch8bcLuCQM87QBatZP1O9 fATmENOqqwtJsBXNZSXxPeaX8J+Npk3QHNN45hDqYW6te+GEFum/n7vDrLDTDKsW IJ0RZ+dGSUmUm/vkWx1TMiR+qwSbJQZ6HOEFW5Q5JkD1ELQVbtdCJUNBaCX3T3GO VdhCWTnYmSP2Nwezgj0CzPy9wJ4Y+82qLXr/DcSd0POI26CToA9OuzbyoVgQ/Mjd egZF4gIh4YfgQ7dnvQDvNLQq8dBD6ld/6aS8x/1CAzcFtT6MARzE/yC5cP2LcoTT SzcIVOOhrSByzygZbjfkceC6Lq+rG2ctUSgiOihTfvWUzpO+kMrmKUUcuI3iZHOV tXKBI+AJGEo0JSWyB+rSq/kG8yFmussLH3bIxGd80BPKxaP0y7M0i7eQULEP2yb5 C5vQ9XqqYKa6ZlIfv4MDRjLn/ydnv5ky5KxM1BRqBiPQQDQK+Jbh+8h2wtAJJcio 85quo2nTdiJBG3UFxw/9/4AIG2ETg7yx3SJ8ecZCgv6OtoXTQ+DjGBWvpHmCSkcM 2tfqhnIbarhG/m3JiP/L =dpL8 -----END PGP SIGNATURE----- --2/5bycvrmDh4d1IB--