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

fix vsnprintf in src/support/asprintf.c for Windows (julia -h doesn't work) #9624

Closed
jakebolewski opened this issue Jan 5, 2015 · 6 comments
Labels
system:windows Affects only Windows

Comments

@jakebolewski
Copy link
Member

No description provided.

@jiahao jiahao added the system:windows Affects only Windows label Jan 5, 2015
@samoconnor
Copy link
Contributor

In srs/support/asprintf.c the buffer realloc() logic does not work on win32 for long input strings.
This code expects vsnprintf() to return a length larger than the input buffer length if the buffer is too small.
On windows vsnprintf() returns -1 if the buffer is too small.

If #define INIT_SZ in asprintf.c is set larger then ./julia.exe -h works.

On Unix (man vsnprintf)
"... if the return value is greater than or equal to the n argument, the string was too short and some of the printed characters were discarded."

On win32 http://msdn.microsoft.com/en-us/library/1kt27hek.aspx
"if the number of characters to write is greater than count, these functions return -1 indicating that output has been truncated."

See: https://github.com/JuliaLang/julia/blob/master/src/support/asprintf.c#L62

@tkelman
Copy link
Contributor

tkelman commented Jan 5, 2015

Wow, thanks @samoconnor. How much larger did you need to make it to get things to work? I'm building now with 256, will see if that's enough.

(Also useful trick for referencing specific lines of code, hit y and github will replace the url with one that references the specific sha, like so)

@samoconnor
Copy link
Contributor

I made it 12800, just to see if it worked.
I guess it has to be as long as the help message.

Sent from my iPhone

On 6 Jan 2015, at 9:20 am, Tony Kelman [email protected] wrote:

Wow, thanks @samoconnor. How much larger did you need to make it to get things to work? I'm building now with 256, will see if that's enough.

(Also useful trick for referencing specific lines of code, hit y and github will replace the url with one that references the specific sha, like so)


Reply to this email directly or view it on GitHub.

@tkelman
Copy link
Contributor

tkelman commented Jan 5, 2015

Yeah, that message is longer than I thought it was. 2048 works at the moment, 1024 doesn't, but that message is also likely to get longer over time.

@samoconnor
Copy link
Contributor

OK, but while tweaking INIT_SZ serves to demonstrate the bug, it doesn't fix the underlying problem, which is that win32 vsnprintf is not POSIX compliant. It looks like asprintf.c needs an #ifdef WINDOWS with an algorithm that doubles the buffer size until it is big enough (or similar).

@tkelman tkelman changed the title Apparently -h / --help command line flags do not work on Windows fix vsnprintf in src/support/asprintf.c for Windows (julia -h doesn't work) Jan 6, 2015
@vtjnash
Copy link
Member

vtjnash commented Jan 7, 2015

vtjnash added a commit that referenced this issue Jan 13, 2015
samoconnor added a commit to samoconnor/julia that referenced this issue Jan 21, 2015
Make uv_write() a function (was a macro) and do c_free in "finally" clause.

Explicit null-termination in jl_safe_printf() to allow for win32's
non-posix vsnprintf behaviour. See also JuliaLang#9624.

Use jl_safe_printf() in profile thread.

Send help message to jl_printf(JL_STDOUT,)  was stderr.
samoconnor added a commit to samoconnor/julia that referenced this issue Feb 2, 2015
Make uv_write() a function (was a macro) and do c_free in "finally" clause.

Explicit null-termination in jl_safe_printf() to allow for win32's
non-posix vsnprintf behaviour. See also JuliaLang#9624.

Use jl_safe_printf() in profile thread.

Send help message to jl_printf(JL_STDOUT,)  was stderr.
samoconnor added a commit to samoconnor/julia that referenced this issue Feb 6, 2015
Make uv_write() a function (was a macro) and do c_free in "finally" clause.

Explicit null-termination in jl_safe_printf() to allow for win32's
non-posix vsnprintf behaviour. See also JuliaLang#9624.

Use jl_safe_printf() in profile thread.

Send help message to jl_printf(JL_STDOUT,)  was stderr.
samoconnor added a commit to samoconnor/julia that referenced this issue Feb 10, 2015
Make uv_write() a function (was a macro) and do c_free in "finally" clause.

Explicit null-termination in jl_safe_printf() to allow for win32's
non-posix vsnprintf behaviour. See also JuliaLang#9624.

Use jl_safe_printf() in profile thread.

Send help message to jl_printf(JL_STDOUT,)  was stderr.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system:windows Affects only Windows
Projects
None yet
Development

No branches or pull requests

5 participants