Skip to content

Prefer size_t over int where possible#415

Open
AZero13 wants to merge 1 commit into
ppp-project:masterfrom
AZero13:work
Open

Prefer size_t over int where possible#415
AZero13 wants to merge 1 commit into
ppp-project:masterfrom
AZero13:work

Conversation

@AZero13

@AZero13 AZero13 commented Apr 19, 2023

Copy link
Copy Markdown
Contributor

This avoids needless truncation, which takes up multiple more instructions on some architectures, especially older ones.

@AZero13 AZero13 force-pushed the work branch 5 times, most recently from cef6f59 to cca060e Compare April 19, 2023 19:44
@Neustradamus Neustradamus requested a review from paulusmack April 21, 2023 21:47
@enaess

enaess commented Apr 23, 2023

Copy link
Copy Markdown
Contributor

These fixes look mostly good. Though, some cases the refactoring changes the structure ... Comments inline to for @paulusmack to review.

Comment thread pppd/auth.c Outdated
Comment thread pppd/plugins/pppoatm/atm.h
Comment thread pppd/tls.c
@paulusmack

Copy link
Copy Markdown
Collaborator

I have mixed feelings about these changes. It's reasonable to use size_t for things that are the length of a structure or a string, but I don't think that the savings in code size will be significant either in space or time. There's also a lot of changes spread out across the source tree which could be better as separate commits.

@AZero13

AZero13 commented May 6, 2023

Copy link
Copy Markdown
Contributor Author

I have mixed feelings about these changes. It's reasonable to use size_t for things that are the length of a structure or a string, but I don't think that the savings in code size will be significant either in space or time. There's also a lot of changes spread out across the source tree which could be better as separate commits.

I think they would be best done at once, that's why, since they all have the same theme.

@paulusmack

Copy link
Copy Markdown
Collaborator

I notice also that the signoff is a noreply.github.com address, which I don't consider adequate.

@Neustradamus Neustradamus added the Author Author answer is needed label Dec 21, 2023
@AZero13 AZero13 force-pushed the work branch 2 times, most recently from dc9e33e to d1cac16 Compare December 21, 2023 21:14
@AZero13

AZero13 commented Dec 21, 2023

Copy link
Copy Markdown
Contributor Author

@Neustradamus Fixed!

@paulusmack paulusmack left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general it seems like there is a bunch of refactoring here plus gratuitous whitespace changes, in addition to the changes mentioned in the commit description (i.e. converting int to size_t). So, at the very least the commit description needs to be more comprehensive. If nothing else it should identify any potential bugs fixed here, though in fact I would prefer the bug fixes to be in separate commits.

I'm not convinced by the rationale that we need to do this to reduce the generated code size. As far as I can see it is only going to reduce the code size on 64-bit machines, not 32-bit machines, some of which might arguably be a bit short on memory. If you have a 64-bit processor you probably have a GB or more of memory, and saving at most a few hundred bytes of instruction memory is going to be in the noise.

Comment thread chat/chat.c Outdated
Comment thread chat/chat.c Outdated
Comment thread chat/chat.c Outdated
Comment thread pppd/chap.c Outdated
Comment thread chat/chat.c
Comment thread pppd/auth.c Outdated
Comment thread pppd/auth.c
Comment thread pppd/main.c Outdated
@Neustradamus

Copy link
Copy Markdown
Member

@AtariDreams: Have you seen @paulusmack comments started:

Note: The other PR has been merged :)

@Neustradamus

Copy link
Copy Markdown
Member

@AtariDreams: Have you looked comments from @paulusmack?

@AZero13

AZero13 commented Apr 26, 2024

Copy link
Copy Markdown
Contributor Author

I'll take a look.

@paulusmack

Copy link
Copy Markdown
Collaborator

As far as I can see, there is no functional change here (or at least, none intended), so I am not going to wait for this.

This avoids needless truncation, which takes up multiple more instructions on some architectures, especially older ones.

Signed-off-by: Rose <gfunni234@gmail.com>
@Neustradamus

Copy link
Copy Markdown
Member

@paulusmack: Have you seen the @RSilicon changes?

Comment thread pppd/main.c

for (uep = userenv_list; uep != NULL; uep = uep->ue_next) {
int i;
size_t i;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a case like this where the variable is a loop index rather than the size or length of something, I'd prefer plain long or unsigned long rather than size_t. Same comment applies in a few other places.

}
va_end(ap);
if (best > -1) (*pos) += best_len;
(*pos) += best_len;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a semantic change; previously the function would return -1 if the string at *pos didn't match any of the argument strings at all, whereas now it will return 0, which callers interpret as a match with the second argument. So now text2qos will parse things incorrectly.

This is an example of why I would have preferred this commit to be split into smaller pieces, for example, four separate commits for chat, pppd, and the pppoatm and pppoe plugins. If you had, I could merge the commits that are OK. As it is, I can't merge any of it.

@paulusmack

Copy link
Copy Markdown
Collaborator

Overall, I would take everything except the pppoatm changes, which don't seem to me to be at all necessary, and in fact wrong, as I commented.

@shahbaz606 shahbaz606 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l

@Neustradamus

Copy link
Copy Markdown
Member

@AZero13: Have you seen the latest @paulusmack comments?

@AZero13

AZero13 commented Mar 13, 2025

Copy link
Copy Markdown
Contributor Author

Yes I will address this now

@Neustradamus

Copy link
Copy Markdown
Member

@AZero13: Have you progressed on it?

@Neustradamus

Copy link
Copy Markdown
Member

@AZero13: It is the end of August 2025, have you progressed on it?
Thanks in advance.

@Neustradamus

Copy link
Copy Markdown
Member

@paulusmack: With the silence of this PR author, maybe you can look to adapt this PR directly?

@Neustradamus

Copy link
Copy Markdown
Member

@AZero13: I have sent you e-mails about your PR.

Can you look your PR?

Thanks in advance.

@AZero13

AZero13 commented Dec 14, 2025

Copy link
Copy Markdown
Contributor Author

Okay, okay okay I will. Yes I will do this

@Neustradamus

Copy link
Copy Markdown
Member

@LumioseSil: Can you check it?

Paul prepares a new build...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author Author answer is needed

Development

Successfully merging this pull request may close these issues.

5 participants