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

Strncpy #809

Closed
wants to merge 2 commits into from
Closed

Strncpy #809

wants to merge 2 commits into from

Conversation

mrannanj
Copy link
Member

@mrannanj mrannanj commented Dec 9, 2024

No description provided.

Comment on lines +100 to +101
strncpy_or_truncate(chr->cutscene_text[i], trn.locales[0]->end_texts[0][i],
strlen(trn.locales[0]->end_texts[0][i]));
Copy link
Contributor

Choose a reason for hiding this comment

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

This is equivalent to calling strcpy(dst, src), and every bit as dangerous.
Do not strncpy(dst, src, strlen(src)).

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, also the omf_calloc is just on the previous line, but let's try strdup then.

Copy link
Contributor

Choose a reason for hiding this comment

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

omf_strdup, i think we have

@@ -62,8 +62,6 @@ int sd_vga_image_decode(sd_rgba_image *dst, const sd_vga_image *src, const vga_p
}

int sd_vga_image_from_png(sd_vga_image *img, const char *filename) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a benefit to these sd_vga_image_from_png changes?
Also: i believe this is now leaking memory, as info_ptr is not consistently passed to png_destroy_read_struct for freeing.

@@ -181,7 +182,7 @@ int sd_chr_load(sd_chr_file *chr, const char *filename) {
for(int m = 0; m < 10; m++) {
if(trn_loaded && trn.enemies[i]->quotes[m]) {
chr->enemies[i]->pilot.quotes[m] = omf_calloc(1, strlen(trn.enemies[i]->quotes[m]) + 1);
strncpy(chr->enemies[i]->pilot.quotes[m], trn.enemies[i]->quotes[m], strlen(trn.enemies[i]->quotes[m]));
strncpy_or_truncate(chr->enemies[i]->pilot.quotes[m], trn.enemies[i]->quotes[m], strlen(trn.enemies[i]->quotes[m]));
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto.
This is equivalent to calling strcpy(dst, src), and every bit as dangerous.
Do not strncpy(dst, src, strlen(src)).

@Nopey
Copy link
Contributor

Nopey commented Dec 9, 2024

didn't notice this was a draft before reviewing it, oops?

@mrannanj mrannanj closed this Dec 9, 2024
@mrannanj mrannanj deleted the strncpy branch December 9, 2024 16:18
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.

2 participants