public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Xi Wang <xi.wang@gmail.com>
Cc: linux-kernel@vger.kernel.org, Alex Elder <elder@dreamhost.com>,
	David Airlie <airlied@linux.ie>,
	Pekka Enberg <penberg@kernel.org>
Subject: Re: [RFC][PATCH] introduce SIZE_MAX
Date: Fri, 20 Apr 2012 16:03:37 -0700	[thread overview]
Message-ID: <20120420160337.479eeac0.akpm@linux-foundation.org> (raw)
In-Reply-To: <1334809671-15288-1-git-send-email-xi.wang@gmail.com>

On Thu, 19 Apr 2012 00:27:51 -0400
Xi Wang <xi.wang@gmail.com> wrote:

> ULONG_MAX is often used to check for integer overflow when calculating
> allocation size.  While ULONG_MAX happens to work on most systems,
> there is no guarantee that `size_t' must be the same size as `long'.
> 
> This patch introduces SIZE_MAX, the maximum value of `size_t', to
> improve portability and readability for allocation size validation.
>
> ...
>
> @@ -331,7 +331,7 @@ static int build_snap_context(struct ceph_snap_realm *realm)
>  
>  	/* alloc new snap context */
>  	err = -ENOMEM;
> -	if (num > (ULONG_MAX - sizeof(*snapc)) / sizeof(u64))
> +	if (num > (SIZE_MAX - sizeof(*snapc)) / sizeof(u64))
>  		goto fail;
>  	snapc = kzalloc(sizeof(*snapc) + num*sizeof(u64), GFP_NOFS);
>  	if (!snapc)

hm, yes, I suppose that's better - hardwiring the assumption that
size_t has type unsigned long is pretty ugly.

Will we need something for ssize_t also?

  reply	other threads:[~2012-04-20 23:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-19  4:27 [RFC][PATCH] introduce SIZE_MAX Xi Wang
2012-04-20 23:03 ` Andrew Morton [this message]
2012-04-21  2:59   ` Xi Wang

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=20120420160337.479eeac0.akpm@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=airlied@linux.ie \
    --cc=elder@dreamhost.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=penberg@kernel.org \
    --cc=xi.wang@gmail.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