public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Is realloc(3) permitted to fail when shrinking a block?
@ 2020-08-11  3:54 孙世龙 sunshilong
  2020-08-11  3:58 ` Dan Kegel
  2020-08-15  7:07 ` Florian Weimer
  0 siblings, 2 replies; 7+ messages in thread
From: 孙世龙 sunshilong @ 2020-08-11  3:54 UTC (permalink / raw)
  To: gcc-help

As the subject, I couldn't find any positive or negative statements
about this matter in the Linux Programmer's Manual.

Could somebody shed some light on this matter?

Thank you for your attention to this matter.
Best regards.
Sunshilong

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is realloc(3) permitted to fail when shrinking a block?
  2020-08-11  3:54 Is realloc(3) permitted to fail when shrinking a block? 孙世龙 sunshilong
@ 2020-08-11  3:58 ` Dan Kegel
  2020-08-11  6:35   ` 孙世龙 sunshilong
  2020-08-15  7:07 ` Florian Weimer
  1 sibling, 1 reply; 7+ messages in thread
From: Dan Kegel @ 2020-08-11  3:58 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: gcc-help

If the heap's corrupt, yes, it can fail...

On Mon, Aug 10, 2020 at 8:54 PM 孙世龙 sunshilong via Gcc-help <
gcc-help@gcc.gnu.org> wrote:

> As the subject, I couldn't find any positive or negative statements
> about this matter in the Linux Programmer's Manual.
>
> Could somebody shed some light on this matter?
>
> Thank you for your attention to this matter.
> Best regards.
> Sunshilong
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is realloc(3) permitted to fail when shrinking a block?
  2020-08-11  3:58 ` Dan Kegel
@ 2020-08-11  6:35   ` 孙世龙 sunshilong
  2020-08-11  7:22     ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: 孙世龙 sunshilong @ 2020-08-11  6:35 UTC (permalink / raw)
  To: Dan Kegel, gcc-help

Thank you for your reply.

>If the heap's corrupt, yes, it can fail...
Could you please explain that in more detail?
What confuses me is that how can it fails to shrink memory while there
is enough memory pointed by the input argument of realloc(3) function
(
i.e. ptr,  here is the declaration of realloc(3):void *realloc(void
*ptr, size_t size);
) at least.

Thank you for your attention to this matter.

On Tue, Aug 11, 2020 at 11:59 AM Dan Kegel <dank@kegel.com> wrote:
>
> If the heap's corrupt, yes, it can fail...
>
> On Mon, Aug 10, 2020 at 8:54 PM 孙世龙 sunshilong via Gcc-help <gcc-help@gcc.gnu.org> wrote:
>>
>> As the subject, I couldn't find any positive or negative statements
>> about this matter in the Linux Programmer's Manual.
>>
>> Could somebody shed some light on this matter?
>>
>> Thank you for your attention to this matter.
>> Best regards.
>> Sunshilong
>>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is realloc(3) permitted to fail when shrinking a block?
  2020-08-11  6:35   ` 孙世龙 sunshilong
@ 2020-08-11  7:22     ` Jonathan Wakely
  2020-08-12 11:23       ` 孙世龙 sunshilong
  0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Wakely @ 2020-08-11  7:22 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: Dan Kegel, gcc-help

On Tue, 11 Aug 2020 at 07:39, 孙世龙 sunshilong via Gcc-help
<gcc-help@gcc.gnu.org> wrote:
>
> Thank you for your reply.
>
> >If the heap's corrupt, yes, it can fail...
> Could you please explain that in more detail?

This mailing list is about GCC, not general C programming. The realloc
function is not part of GCC.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is realloc(3) permitted to fail when shrinking a block?
  2020-08-11  7:22     ` Jonathan Wakely
@ 2020-08-12 11:23       ` 孙世龙 sunshilong
  2020-08-12 11:59         ` Jonathan Wakely
  0 siblings, 1 reply; 7+ messages in thread
From: 孙世龙 sunshilong @ 2020-08-12 11:23 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: Dan Kegel, gcc-help

>This mailing list is about GCC, not general C programming. The realloc
>function is not part of GCC.
Sorry, I didn't notice it.
I took it granted that libc is part of the GCC since there is a folder
named "libstdc++" in the Github of GCC(i.e.
https://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3).

One more question arises, why there is no library for libc whereas
libstdc++ is provided by GCC?

Thank you for your attention to this matter.

On Tue, Aug 11, 2020 at 3:22 PM Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
> On Tue, 11 Aug 2020 at 07:39, 孙世龙 sunshilong via Gcc-help
> <gcc-help@gcc.gnu.org> wrote:
> >
> > Thank you for your reply.
> >
> > >If the heap's corrupt, yes, it can fail...
> > Could you please explain that in more detail?
>
> This mailing list is about GCC, not general C programming. The realloc
> function is not part of GCC.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is realloc(3) permitted to fail when shrinking a block?
  2020-08-12 11:23       ` 孙世龙 sunshilong
@ 2020-08-12 11:59         ` Jonathan Wakely
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Wakely @ 2020-08-12 11:59 UTC (permalink / raw)
  To: 孙世龙 sunshilong; +Cc: Dan Kegel, gcc-help

On Wed, 12 Aug 2020 at 12:23, 孙世龙 sunshilong <sunshilong369@gmail.com> wrote:
>
> >This mailing list is about GCC, not general C programming. The realloc
> >function is not part of GCC.
> Sorry, I didn't notice it.
> I took it granted that libc is part of the GCC since there is a folder
> named "libstdc++" in the Github of GCC(i.e.
> https://github.com/gcc-mirror/gcc/tree/master/libstdc%2B%2B-v3).
>
> One more question arises, why there is no library for libc whereas
> libstdc++ is provided by GCC?

Because every unix-like OS already has its own libc, because C and
UNIX were developed hand-in-hand.

Traditionally they didn't have a C++ library, so a C++ compiler has to
provide the C++ library.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Is realloc(3) permitted to fail when shrinking a block?
  2020-08-11  3:54 Is realloc(3) permitted to fail when shrinking a block? 孙世龙 sunshilong
  2020-08-11  3:58 ` Dan Kegel
@ 2020-08-15  7:07 ` Florian Weimer
  1 sibling, 0 replies; 7+ messages in thread
From: Florian Weimer @ 2020-08-15  7:07 UTC (permalink / raw)
  To: 孙世龙 sunshilong via Gcc-help

* 孙世龙 sunshilong via Gcc-help:

> As the subject, I couldn't find any positive or negative statements
> about this matter in the Linux Programmer's Manual.
>
> Could somebody shed some light on this matter?

As a quality-of-implementation issue, I would not expect realloc to
fail when shrinking a block.  As a fallback, it can always keep the
block in its original size, not changing anything.

The C standard does not require that reducing the size cannot lead to
failure.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-08-15  7:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-11  3:54 Is realloc(3) permitted to fail when shrinking a block? 孙世龙 sunshilong
2020-08-11  3:58 ` Dan Kegel
2020-08-11  6:35   ` 孙世龙 sunshilong
2020-08-11  7:22     ` Jonathan Wakely
2020-08-12 11:23       ` 孙世龙 sunshilong
2020-08-12 11:59         ` Jonathan Wakely
2020-08-15  7:07 ` Florian Weimer

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 read-only IMAP folder(s) and NNTP newsgroup(s).