Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor out hostmask formatting #880

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jesopo
Copy link
Member

@jesopo jesopo commented Jul 20, 2022

i plan to use this function in more places that already format hostmasks, but i wanted to open this PR early to see if this is the right way of going about this. returning a pointer means (i believe) that you can't call this and store its results consecutively, but i think that might be an ok cost for not having to free things

Copy link
Member

@ilbelkyr ilbelkyr left a comment

Choose a reason for hiding this comment

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

moving code like this into helper functions is an idea i'm in favor of, i think, especially if it's going to be reused more

as for returning the same buffer each time, if the caller needs to store it they can just sstrdup() it i'd say

@@ -21,6 +21,8 @@ static mowgli_heap_t *user_heap = NULL;
mowgli_patricia_t *userlist;
mowgli_patricia_t *uidlist;

char hostmaskbuf[NICKLEN + USERLEN + HOSTLEN + 2];
Copy link
Member

Choose a reason for hiding this comment

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

this needs an extra byte for the string terminator; i'd also add a comment explaining where the number comes from to avoid people making mistakes in the future

you could also put this as static inside the format_hostmask function i think; might be a bit cleaner?

const char *
format_hostmask(const struct user *user, const enum host_type type)
{
sprintf(hostmaskbuf, "%s!%s!%s", user->nick, user->user, user->vhost);
Copy link
Member

Choose a reason for hiding this comment

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

this currently just does user->vhost without checking the requested host type

i'd probably use snprintf with sizeof hostmaskbuf here for safety

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants