git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Torsten Bögershausen" <tboegi@web.de>
To: Martin Koegler <martin.koegler@chello.at>
Cc: Junio C Hamano <gitster@pobox.com>,
	Ramsay Jones <ramsay@ramsayjones.plus.com>,
	git@vger.kernel.org, Johannes.Schindelin@gmx.de
Subject: Re: [PATCH 1/9] Convert pack-objects to size_t
Date: Thu, 17 Aug 2017 12:38:04 +0200	[thread overview]
Message-ID: <20170817103804.GA18336@tor.lan> (raw)
In-Reply-To: <20170816202238.GA3008@mail.zuhause>

On Wed, Aug 16, 2017 at 10:22:39PM +0200, Martin Koegler wrote:
> On Mon, Aug 14, 2017 at 10:08:05AM -0700, Junio C Hamano wrote:
> >    It may help reducing the maintenance if we introduced obj_size_t
> >    that is defined to be size_t for now, so that we can later swap
> >    it to ofs_t or some larger type when we know we do need to
> >    support objects whose size cannot be expressed in size_t, but I
> >    do not offhand know what the pros-and-cons with such an approach
> >    would look like.
> 
> Where should the use of obj_size_t end and the use of size_t start? 
> 
> We often determine a object size and then pass it to malloc. 
> We would start with a larger datatyp and then truncate for memory allocation, which use size_t.

The truncation is done with xsize_t:
The "old" sha1_file.c has something like this:
    idx_size = xsize_t(st.st_size);

I personally don't think that obj_size_t gives us so much.
There are "objects" which are "on disk", and they may have a length off_t,
And there are "objects" loaded into memory, and they have a length size_t.
And everybody can check that we use the right type.
Additionally I don't like it very much, when object size in memory is counted
in a 64 bit value (and this will happen if  obj_size_ = off_t == 64bit)

Anyhow, to answer your question:
All calles xmalloc() must be prepared like this:

p = xmalloc(xsize_t(size_of_object));

That should do the trick.

> 
> Regards,
> Martin

      reply	other threads:[~2017-08-17 10:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-12  8:47 [PATCH 1/9] Convert pack-objects to size_t Martin Koegler
2017-08-12  8:47 ` [PATCH 2/9] Convert index-pack " Martin Koegler
2017-08-12 13:51   ` Ramsay Jones
2017-08-12  8:47 ` [PATCH 3/9] Convert unpack-objects " Martin Koegler
2017-08-12 14:07   ` Martin Ågren
2017-08-13 18:25     ` Martin Koegler
2017-08-12  8:47 ` [PATCH 4/9] Convert archive functions " Martin Koegler
2017-08-12  8:47 ` [PATCH 5/9] Convert various things " Martin Koegler
2017-08-12 13:27   ` Martin Ågren
2017-08-13 17:48     ` Martin Koegler
2017-08-12  8:47 ` [PATCH 6/9] Use size_t for config parsing Martin Koegler
2017-08-12  8:47 ` [PATCH 7/9] Convert ref-filter to size_t Martin Koegler
2017-08-12  8:47 ` [PATCH 8/9] Convert tree-walk " Martin Koegler
2017-08-12  8:47 ` [PATCH 9/9] Convert xdiff-interface " Martin Koegler
2017-08-12  9:59 ` [PATCH 1/9] Convert pack-objects " Torsten Bögershausen
2017-08-13 18:27   ` Martin Koegler
2017-08-12 13:47 ` Ramsay Jones
2017-08-13 18:30   ` Martin Koegler
2017-08-13 19:45     ` Ramsay Jones
2017-08-13 22:15       ` Junio C Hamano
2017-08-14 17:08         ` Junio C Hamano
2017-08-14 19:31           ` Ramsay Jones
2017-08-14 19:58             ` Junio C Hamano
2017-08-14 20:32             ` Torsten Bögershausen
2017-08-15  0:30               ` Ramsay Jones
2017-08-16 20:22           ` Martin Koegler
2017-08-17 10:38             ` Torsten Bögershausen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170817103804.GA18336@tor.lan \
    --to=tboegi@web.de \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=martin.koegler@chello.at \
    --cc=ramsay@ramsayjones.plus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).