linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Ramsay Jones <ramsay@ramsayjones.plus.com>
Cc: linux-sparse@vger.kernel.org
Subject: Re: [PATCH 6/6] ptrlist: change return value of linearize_ptr_list()/ptr_list_to_array()
Date: Sat, 6 Mar 2021 18:46:04 +0100	[thread overview]
Message-ID: <20210306174604.iki62afa2rv7xsvw@mail> (raw)
In-Reply-To: <b9f7ecdf-ee6d-0c77-560e-e05b26bcec02@ramsayjones.plus.com>

On Sat, Mar 06, 2021 at 04:43:21PM +0000, Ramsay Jones wrote:
> On 06/03/2021 10:05, Luc Van Oostenryck wrote:
> > Change this, so that this function returns the total number of
> > entries in the list, much like it's done for snprintf().
> 
> But this requires setting max == 0, right? This isn't documented.

No no, there is nothing special with max == 0 at the interface level.
If the list contains 3 elements but you're only interested in the cases
it contains 2, you now call:
	... array[2];
	int nbr = linearize_ptr_list(list, array, 2);
and it'll only fill 2 elements but it will return 3, so can you write:
	if (nbr == 2) {
		... do stuff ...
	}
IOW, it returns the number of elements that would have been written
to the array if 'max' would have been infinite.

Previously, it would have returned 2 because the return value was
capped to 'max' / it returned he number of elements written. So you
had no idea if the list effectively contained only 2 elements of if
there was some more and so you had to call it with one extra element
to check this:
	... array[3];
	int nbr = linearize_ptr_list(list, array, 3);
	if (nbr == 2) {
		...
	}

Thanks for noticing all these typos,
-- Luc

      reply	other threads:[~2021-03-06 17:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-06 10:05 [PATCH 0/6] small changes to ptrlist API Luc Van Oostenryck
2021-03-06 10:05 ` [PATCH 1/6] ptrlist: ~fix TYPEOF() Luc Van Oostenryck
2021-03-06 16:19   ` Ramsay Jones
2021-03-06 10:05 ` [PATCH 2/6] ptrlist: change TYPEOF() into PTRLIST_TYPE() Luc Van Oostenryck
2021-03-06 16:20   ` Ramsay Jones
2021-03-06 10:05 ` [PATCH 3/6] ptrlist: add pop_ptr_list() Luc Van Oostenryck
2021-03-06 16:22   ` Ramsay Jones
2021-03-06 10:05 ` [PATCH 4/6] ptrlist: use ptr_list_nth() instead of linearize_ptr_list() Luc Van Oostenryck
2021-03-06 16:24   ` Ramsay Jones
2021-03-06 10:05 ` [PATCH 5/6] ptrlist: make linearize_ptr_list() generic Luc Van Oostenryck
2021-03-06 16:35   ` Ramsay Jones
2021-03-06 22:05     ` Luc Van Oostenryck
2021-03-06 10:05 ` [PATCH 6/6] ptrlist: change return value of linearize_ptr_list()/ptr_list_to_array() Luc Van Oostenryck
2021-03-06 16:43   ` Ramsay Jones
2021-03-06 17:46     ` Luc Van Oostenryck [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=20210306174604.iki62afa2rv7xsvw@mail \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --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).