Skip to content

Fix error C2664 on MSVC 2015#78

Merged
nmoinvaz merged 1 commit intozlib-ng:masterfrom
inequation:master
Nov 14, 2016
Merged

Fix error C2664 on MSVC 2015#78
nmoinvaz merged 1 commit intozlib-ng:masterfrom
inequation:master

Conversation

@inequation
Copy link
Copy Markdown
Contributor

I'm compiling minizip in my project by #including its source code inline (namely, unzip.c and ioapi.c) in MSVC 2015. I'll let the compiler speak for itself:

ioapi.c(201): error C2664: 'char *strncpy(char *,const char *,std::size_t)': cannot convert argument 2 from 'void *' to 'const char *'
ioapi.c(201): note: Conversion from 'void*' to pointer to non-'void' requires an explicit cast

There are two more in the same vein. This PR is a trivial fix for these errors.

I'll let the compiler speak for itself:
ioapi.c(201): error C2664: 'char *strncpy(char *,const char *,std::size_t)': cannot convert argument 2 from 'void *' to 'const char *'
ioapi.c(201): note: Conversion from 'void*' to pointer to non-'void' requires an explicit cast
A trivial fix, this is.
@MacGritsch
Copy link
Copy Markdown
Contributor

Why not change "void *filename" to "char *filename" in the struct?

@inequation
Copy link
Copy Markdown
Contributor Author

Yes, that would probably be better still. I've simply chosen to do the casting because the surrounding code does the same, including the API (cf. lines 122-123, 146 etc.).

I can't see any reason to use a void pointer in the first place, though. Perhaps this was in anticipation of also supporting wide characters, or using miscellaneous data structure as "filename" (i.e. not necessarily strings), but then using regular char string functions probably defeats the purpose.

@MacGritsch
Copy link
Copy Markdown
Contributor

I saw the lines above your changes and there the malloc-result is casted to (char *) so I think it was changed later to void...

@inequation
Copy link
Copy Markdown
Contributor Author

Digging through history, it's been like this since January 2012 (commit 6d35b6b; also, GitHub is very shitty at displaying this diff for whatever reason, I had to use an external tool to view it 😕). Apparently, this data structure is used for generating part-numbered filenames for archives spanning multiple disks.

I'm all for changing the field type instead, but I'd like a project maintainer to weigh in first. :)

@nmoinvaz
Copy link
Copy Markdown
Member

nmoinvaz commented Nov 9, 2016

Change looks good.

@inequation
Copy link
Copy Markdown
Contributor Author

@nmoinvaz Great! Can we expect it to be merged?

@nmoinvaz nmoinvaz merged commit 7b8e226 into zlib-ng:master Nov 14, 2016
@inequation
Copy link
Copy Markdown
Contributor Author

Thank you!

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.

3 participants