Re: Whaddaya think?

Liste des GroupesRevenir à l c 
Sujet : Re: Whaddaya think?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.c
Date : 16. Jun 2024, 17:37:34
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4n0rv$41ir$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 16.06.2024 13:31, Michael S wrote:
On Sun, 16 Jun 2024 12:03:21 +0200
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
 
On 16.06.2024 11:38, Michael S wrote:
 
>
Again; which ones?
>
Janis
>
[...] 
>
>
 
The main misconceptions are about what is returned by fgets() and by
realloc().
fgets() returns its first argument in all cases except EOF or FS read
error. That includes the case when the buffer is too short to
accommodate full input line.

   fgets() return s on success, and NULL on error or when end
           of file occurs while no characters have been read.

I am interested in the success case, thus "fgets() != NULL".
The buffer size is controlled by the second function parameter.

 
With realloc() there are two issues:
1. It can sometimes return its first argument, but does not have to. In
scenario like yours it will return a different pointer quite soon.
2. When realloc() returns NULL, it does not de-allocate its first
argument.
 
The second case, of course, is not important in practice, because in
practice you're very unlikely to see realloc() returning NULL, and if
nevertheless it did happen, you program is unlikely to survive and give
meaningful result anyway. Still, here on c.l.c we like to pretend that
we can meaningfully handle allocation failures.

You may provide "correct" code (if you think mine is wrong). Or just
inspect how it behaves; here's the output after two printf's added:

$ printf "123 456 789 101112 77 88 99 101 999" | realloc
+++>123 456 78<+++
===>123 456 78<===
+++>9 101112 7<+++
===>123 456 789 101112 7<===
+++>7 88 99 10<+++
===>123 456 789 101112 77 88 99 10<===
+++>1 999<+++
===>123 456 789 101112 77 88 99 101 999<===
123 456 789 101112 77 88 99 101 999

The +++data+++ is the chunk read, and the ===data=== is the overall
buffer content, and the final line again the result (as before, with
the added newline as documented for puts()).

Even though my code is just an "ad hoc test code" to demonstrate the
procedure I outlined - and as such test code certainly lacking quite
some error handling and much more - it does exactly what I intended it
to do, and what I've implemented according to what I read in the man
pages. I cannot see any "misconception", it does what was _intended_.

There's indeed one point that I _deliberately_ ignored for the test
code; actually the point you mentioned as "not important in practice".

Again: You may provide "correct" code (if you think mine is "wrong"),
or "better" code, usable for production instead of a test code.

But your tone and statements were (as observed so often) inadequate;
I quote from your post that started the subthread:
"However it looks unlikely that it does what you meant for it to do."

It does exactly what I meant to do (as you can see in the logs above).

Janis


Date Sujet#  Auteur
15 Jun 24 * Whaddaya think?96DFS
15 Jun 24 +- Re: Whaddaya think?1Malcolm McLean
16 Jun 24 +* Re: Whaddaya think?5Ben Bacarisse
16 Jun 24 i+* Re: Whaddaya think?2bart
16 Jun 24 ii`- Re: Whaddaya think?1Ben Bacarisse
16 Jun 24 i`* Re: Whaddaya think?2DFS
17 Jun 24 i `- Re: Whaddaya think?1Ben Bacarisse
16 Jun 24 +* Re: Whaddaya think?23Keith Thompson
16 Jun 24 i`* Re: Whaddaya think?22DFS
16 Jun 24 i +- Re: Whaddaya think?1Keith Thompson
17 Jun 24 i +* Re: Whaddaya think?19James Kuyper
17 Jun 24 i i+- Re: Whaddaya think?1Tim Rentsch
17 Jun 24 i i+* Re: Whaddaya think?13Kaz Kylheku
17 Jun 24 i ii+- Re: Whaddaya think?1Chris M. Thomasson
17 Jun 24 i ii+* Re: Whaddaya think?6DFS
17 Jun 24 i iii`* Re: Whaddaya think?5Richard Harnden
17 Jun 24 i iii +- Re: Whaddaya think?1David Brown
23 Jun 24 i iii `* Re: Whaddaya think?3Kaz Kylheku
23 Jun 24 i iii  +- Re: Whaddaya think?1Keith Thompson
23 Jun 24 i iii  `- Re: Whaddaya think?1Phil Carmody
18 Jun 24 i ii`* Re: Whaddaya think?5Tim Rentsch
18 Jun 24 i ii `* Re: Whaddaya think?4Keith Thompson
19 Jun 24 i ii  `* Re: Whaddaya think?3Tim Rentsch
19 Jun 24 i ii   `* Re: Whaddaya think?2Keith Thompson
19 Jun 24 i ii    `- Re: Whaddaya think?1Kaz Kylheku
17 Jun 24 i i`* Re: Whaddaya think?4DFS
17 Jun 24 i i `* Re: Whaddaya think?3Ben Bacarisse
18 Jun 24 i i  `* Re: Whaddaya think?2Janis Papanagnou
18 Jun 24 i i   `- Re: Whaddaya think?1Keith Thompson
17 Jun 24 i `- Re: Whaddaya think?1James Kuyper
16 Jun 24 +* Re: Whaddaya think?60Michael S
16 Jun 24 i+* Re: Whaddaya think?58Lawrence D'Oliveiro
16 Jun 24 ii`* Re: Whaddaya think?57Janis Papanagnou
16 Jun 24 ii +* Re: Whaddaya think?8Keith Thompson
16 Jun 24 ii i+- Re: Whaddaya think?1Lawrence D'Oliveiro
16 Jun 24 ii i`* Re: Whaddaya think?6Janis Papanagnou
16 Jun 24 ii i `* Re: Whaddaya think?5DFS
16 Jun 24 ii i  `* Re: Whaddaya think?4David Brown
16 Jun 24 ii i   +* Re: Whaddaya think?2bart
17 Jun 24 ii i   i`- Re: Whaddaya think?1David Brown
17 Jun 24 ii i   `- Re: Whaddaya think?1DFS
16 Jun 24 ii +* Re: Whaddaya think?45Janis Papanagnou
16 Jun 24 ii i`* Re: Whaddaya think?44Keith Thompson
16 Jun 24 ii i `* Re: Whaddaya think?43Janis Papanagnou
16 Jun 24 ii i  +* Re: Whaddaya think?20Keith Thompson
16 Jun 24 ii i  i`* Re: Whaddaya think?19Janis Papanagnou
16 Jun 24 ii i  i +* Re: Whaddaya think?2Malcolm McLean
16 Jun 24 ii i  i i`- Re: Whaddaya think?1Janis Papanagnou
16 Jun 24 ii i  i `* Re: Whaddaya think?16Keith Thompson
17 Jun 24 ii i  i  `* Re: Whaddaya think?15Janis Papanagnou
17 Jun 24 ii i  i   +* Re: Whaddaya think?12Keith Thompson
17 Jun 24 ii i  i   i`* Re: Whaddaya think?11Janis Papanagnou
17 Jun 24 ii i  i   i +* Re: Whaddaya think?5James Kuyper
18 Jun 24 ii i  i   i i+- Re: Whaddaya think?1Keith Thompson
18 Jun 24 ii i  i   i i`* Re: Whaddaya think?3Janis Papanagnou
18 Jun 24 ii i  i   i i +- Re: Whaddaya think?1James Kuyper
18 Jun 24 ii i  i   i i `- Re: Whaddaya think?1Keith Thompson
18 Jun 24 ii i  i   i `* Re: Whaddaya think?5Keith Thompson
18 Jun 24 ii i  i   i  +- Re: Whaddaya think?1Janis Papanagnou
19 Jun 24 ii i  i   i  `* Re: Whaddaya think?3Keith Thompson
19 Jun 24 ii i  i   i   `* Re: Whaddaya think?2David Brown
19 Jun 24 ii i  i   i    `- Re: Whaddaya think?1Keith Thompson
17 Jun 24 ii i  i   `* Re: Whaddaya think?2James Kuyper
17 Jun 24 ii i  i    `- Re: Whaddaya think?1Janis Papanagnou
16 Jun 24 ii i  +* Re: Whaddaya think?7Michael S
16 Jun 24 ii i  i`* Re: Whaddaya think?6Janis Papanagnou
16 Jun 24 ii i  i `* Re: Whaddaya think?5Michael S
16 Jun 24 ii i  i  `* Re: Whaddaya think?4Janis Papanagnou
16 Jun 24 ii i  i   `* Re: Whaddaya think?3Michael S
16 Jun 24 ii i  i    `* Re: Whaddaya think?2Janis Papanagnou
16 Jun 24 ii i  i     `- Re: Whaddaya think?1Michael S
17 Jun 24 ii i  `* Re: Whaddaya think?15Keith Thompson
17 Jun 24 ii i   +* Re: Whaddaya think?11Tim Rentsch
17 Jun 24 ii i   i+* Re: Whaddaya think?8Janis Papanagnou
17 Jun 24 ii i   ii+* Re: Whaddaya think?6DFS
17 Jun 24 ii i   iii+* Re: Whaddaya think?2Chris M. Thomasson
18 Jun 24 ii i   iiii`- Re: Whaddaya think?1Keith Thompson
18 Jun 24 ii i   iii+* Re: Whaddaya think?2Keith Thompson
18 Jun 24 ii i   iiii`- Re: Whaddaya think?1David Brown
18 Jun 24 ii i   iii`- Re: Whaddaya think?1Janis Papanagnou
18 Jun 24 ii i   ii`- Re: Whaddaya think?1Tim Rentsch
17 Jun 24 ii i   i`* Re: Whaddaya think?2James Kuyper
19 Jun 24 ii i   i `- Re: Whaddaya think?1Tim Rentsch
17 Jun 24 ii i   `* Re: Whaddaya think?3Janis Papanagnou
17 Jun 24 ii i    `* Re: Whaddaya think?2Keith Thompson
17 Jun 24 ii i     `- Re: Whaddaya think?1Janis Papanagnou
16 Jun 24 ii +- Re: Whaddaya think?1Malcolm McLean
16 Jun 24 ii `* Re: Whaddaya think?2Michael S
16 Jun 24 ii  `- Re: Whaddaya think?1Janis Papanagnou
16 Jun 24 i`- Re: Whaddaya think?1DFS
16 Jun 24 `* Re: Whaddaya think?6Lew Pitcher
16 Jun 24  +- Re: Whaddaya think?1Malcolm McLean
18 Jun 24  +- Re: Whaddaya think?1Lawrence D'Oliveiro
25 Jun 24  `* Re: Whaddaya think?3Lew Pitcher
25 Jun 24   `* Re: Whaddaya think?2DFS
25 Jun 24    `- Re: Whaddaya think?1Lew Pitcher

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal