public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Kitt <steve@sk2.org>
To: Jakub Wilk <jwilk@jwilk.net>
Cc: Alejandro Colomar <alx.manpages@gmail.com>,
	Michael Kerrisk <mtk.manpages@gmail.com>,
	<linux-man@vger.kernel.org>
Subject: Re: [PATCH 9/9] malloc_info.3: Use intptr_t to store pointers
Date: Sat, 8 Jan 2022 18:09:07 +0100	[thread overview]
Message-ID: <20220108180907.7e06d7d3@heffalump.sk2.org> (raw)
In-Reply-To: <20220108103041.ui4uiqfpdrn5mt33@jwilk.net>

[-- Attachment #1: Type: text/plain, Size: 1819 bytes --]

On Sat, 8 Jan 2022 11:30:41 +0100, Jakub Wilk <jwilk@jwilk.net> wrote:
> For the record, this is what you get when you compile the original code 
> on a 64-bit architecture:
> 
>     $ gcc -Wall -pthread malloc_info-example.c
>     malloc_info-example.c: In function 'thread_func':
>     malloc_info-example.c:16:14: warning: cast from pointer to integer of
> different size [-Wpointer-to-int-cast] 16 |     int tn = (int) arg;
>           |              ^
>     malloc_info-example.c: In function 'main':
>     malloc_info-example.c:57:32: warning: cast to pointer from integer of
> different size [-Wint-to-pointer-cast] 57 |
> (void *) tn); |                                ^
> 
> * Alejandro Colomar <alx.manpages@gmail.com>, 2022-01-08, 03:25:
> >On 1/7/22 17:46, Stephen Kitt wrote:  
> >>int isn't large enough to store pointers on all platforms, use 
> >>intptr_t instead.  
> >
> >Well, since the pointer came from a previous 'int', there should be no 
> >problem.  But since the C language (or even POSIX) is very permissive 
> >about what a conforming implementation can do with pointers, and it 
> >only guarantees conversions to/from [u]intptr_t, I'd take this patch 
> >for correctness.  However...  
> 
> The standards guarantee that void* → intptr_t → void* round-trips, 
> but that's not what this code does.
> 
> The example converts int → void* → int. Changing int to intptr_t makes 
> the compiler warnings go away, but I don't think it improves correctness 
> in any way.

Agreed, the example is just trying to pass an int into the function given to
pthread_create. AFAICT the only requirement for correctness is that the type
used is at most the size of void *.

It’s probably not worth bothering about the compiler warning...

Regards,

Stephen

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-01-08 17:09 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-07 16:46 [PATCH 1/9] Add a target to check example programs Stephen Kitt
2022-01-07 16:46 ` [PATCH 2/9] seccomp.2: Use syscall() in the example code Stephen Kitt
2022-01-08  1:18   ` Alejandro Colomar (man-pages)
2022-01-07 16:46 ` [PATCH 3/9] inet.3: Switch to _DEFAULT_SOURCE in the example Stephen Kitt
2022-01-08  1:26   ` Alejandro Colomar (man-pages)
2022-01-08  9:06     ` Stephen Kitt
2022-01-07 16:46 ` [PATCH 4/9] matherr.3: Exclude the example from analysis Stephen Kitt
2022-01-08  1:31   ` Alejandro Colomar (man-pages)
2022-01-08  9:12     ` Stephen Kitt
2022-01-07 16:46 ` [PATCH 5/9] mq_notify.3: Add signal.h for SIGEV_THREAD Stephen Kitt
2022-01-08  1:38   ` Alejandro Colomar (man-pages)
2022-01-07 16:46 ` [PATCH 6/9] newlocale.3: Use LC_GLOBAL_LOCALE, not ..._HANDLE Stephen Kitt
2022-01-08  1:41   ` Alejandro Colomar (man-pages)
2022-01-08  9:13     ` Jakub Wilk
2022-01-08 17:58       ` Alejandro Colomar (man-pages)
2022-01-07 16:46 ` [PATCH 7/9] pkeys.7: Update the example to match glibc Stephen Kitt
2022-01-08  1:59   ` Alejandro Colomar (man-pages)
2022-01-08 14:18     ` Stephen Kitt
2022-01-08 19:20       ` Alejandro Colomar (man-pages)
2022-01-07 16:46 ` [PATCH 8/9] strtok.3: Enable example analysis, fix declaration Stephen Kitt
2022-01-08  2:04   ` Alejandro Colomar (man-pages)
2022-01-07 16:46 ` [PATCH 9/9] malloc_info.3: Use intptr_t to store pointers Stephen Kitt
2022-01-08  2:25   ` Alejandro Colomar (man-pages)
2022-01-08 10:30     ` Jakub Wilk
2022-01-08 17:09       ` Stephen Kitt [this message]
2022-01-08 19:17       ` Alejandro Colomar (man-pages)
2022-01-08  1:15 ` [PATCH 1/9] Add a target to check example programs Alejandro Colomar (man-pages)
2022-01-08  9:22   ` Stephen Kitt
2022-01-08 19:05     ` Alejandro Colomar (man-pages)
2022-01-08 19:38       ` Alejandro Colomar (man-pages)
2022-01-08  2:02 ` Alejandro Colomar (man-pages)

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=20220108180907.7e06d7d3@heffalump.sk2.org \
    --to=steve@sk2.org \
    --cc=alx.manpages@gmail.com \
    --cc=jwilk@jwilk.net \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@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