|
From: Shigeharu T. <sh...@ie...> - 2011-10-06 08:16:18
|
shige 10/06 2011
----------------
I saw that gnuplot.exe of CVS version compiled by VC++ reports
some errors for demo/stringvar.dem. Two errors of them are for
system() and they are not strange because I compiled without the
macro PIPES. But the rest one is odd:
foo = sprintf("%40d %40d %40d %40d %40d %40d",1,2,3,4,5,6)
^
"stringvar.dem", line 59: undefined value
The gnuplot show no erorr message for the command
foo = sprintf("%83d",1)
but it show the same error message above for the command
foo = sprintf("%84d",1)
I don't know why this happens.
+========================================================+
Shigeharu TAKENO NIigata Institute of Technology
kashiwazaki,Niigata 945-1195 JAPAN
sh...@ie... TEL(&FAX): +81-257-22-8161
+========================================================+
|
|
From: Hans-Bernhard B. <HBB...@t-...> - 2011-10-06 22:46:11
|
On 06.10.2011 10:01, Shigeharu TAKENO wrote:
> I saw that gnuplot.exe of CVS version compiled by VC++ reports
[...]
> foo = sprintf("%40d %40d %40d %40d %40d %40d",1,2,3,4,5,6)
> ^
> "stringvar.dem", line 59: undefined value
For what it's worth: this program doesn't appear in gnuplot.exe compiled
by Open Watcom.
> The gnuplot show no erorr message for the command
>
> foo = sprintf("%83d",1)
>
> but it show the same error message above for the command
>
> foo = sprintf("%84d",1)
This doesn't cause problem either.
The root of the problem appears to be the buffer size computation and
subsequent realloc()ation in f_sprintf(). The number 84 is magic
because it's 84 plus the length of the format string "%84d". Go figure.
|
|
From: Ethan M. <merritt@u.washington.edu> - 2011-10-06 23:23:36
|
On Thursday, October 06, 2011 03:46:13 pm Hans-Bernhard Bröker wrote:
> On 06.10.2011 10:01, Shigeharu TAKENO wrote:
>
> > I saw that gnuplot.exe of CVS version compiled by VC++ reports
> [...]
> > foo = sprintf("%40d %40d %40d %40d %40d %40d",1,2,3,4,5,6)
> > ^
> > "stringvar.dem", line 59: undefined value
>
> For what it's worth: this program doesn't appear in gnuplot.exe compiled
> by Open Watcom.
>
> > The gnuplot show no erorr message for the command
> >
> > foo = sprintf("%83d",1)
> >
> > but it show the same error message above for the command
> >
> > foo = sprintf("%84d",1)
>
> This doesn't cause problem either.
>
> The root of the problem appears to be the buffer size computation and
> subsequent realloc()ation in f_sprintf(). The number 84 is magic
> because it's 84 plus the length of the format string "%84d". Go figure.
The problem occurs when the platform/compiler does not support snprintf.
f_sprintf() has:
#ifdef HAVE_SNPRINTF
/* Use the format to print next arg */
... this code works fine ...
#else
/* FIXME - this is bad; we should dummy up an snprintf equivalent */
... this code triggers a buffer overflow if the format width is too large
#endif
So the FIXME comment is correct.
Ethan
--
Ethan A Merritt
Biomolecular Structure Center, K-428 Health Sciences Bldg
University of Washington, Seattle 98195-7742
|
|
From: Ethan M. <merritt@u.washington.edu> - 2011-10-06 23:34:48
|
On Thursday, October 06, 2011 04:22:52 pm Ethan Merritt wrote:
> On Thursday, October 06, 2011 03:46:13 pm Hans-Bernhard Br�ker wrote:
> > On 06.10.2011 10:01, Shigeharu TAKENO wrote:
> >
> > > I saw that gnuplot.exe of CVS version compiled by VC++ reports
> > [...]
> > > foo = sprintf("%40d %40d %40d %40d %40d %40d",1,2,3,4,5,6)
> > > ^
> > > "stringvar.dem", line 59: undefined value
> >
> > For what it's worth: this program doesn't appear in gnuplot.exe compiled
> > by Open Watcom.
> >
> > > The gnuplot show no erorr message for the command
> > >
> > > foo = sprintf("%83d",1)
> > >
> > > but it show the same error message above for the command
> > >
> > > foo = sprintf("%84d",1)
> >
> > This doesn't cause problem either.
> >
> > The root of the problem appears to be the buffer size computation and
> > subsequent realloc()ation in f_sprintf(). The number 84 is magic
> > because it's 84 plus the length of the format string "%84d". Go figure.
>
> The problem occurs when the platform/compiler does not support snprintf.
> f_sprintf() has:
>
> #ifdef HAVE_SNPRINTF
> /* Use the format to print next arg */
> ... this code works fine ...
> #else
> /* FIXME - this is bad; we should dummy up an snprintf equivalent */
> ... this code triggers a buffer overflow if the format width is too large
> #endif
Some Googling suggests that VC++ may work if you do
#define snprintf _snprintf
This would have to go in some header or configuration file,
along with HAVE_SNPRINTF.
--
Ethan A Merritt
Biomolecular Structure Center, K-428 Health Sciences Bldg
University of Washington, Seattle 98195-7742
|
|
From: Shigeharu T. <sh...@ie...> - 2011-10-07 02:20:10
|
shige 10/07 2011
----------------
Ethan Merritt <merritt@u.washington.edu> wrote:
| Some Googling suggests that VC++ may work if you do
| #define snprintf _snprintf
|
| This would have to go in some header or configuration file,
| along with HAVE_SNPRINTF.
Thank you for your reply. But, we already use them (see
config/config.nt).
+========================================================+
Shigeharu TAKENO NIigata Institute of Technology
kashiwazaki,Niigata 945-1195 JAPAN
sh...@ie... TEL(&FAX): +81-257-22-8161
+========================================================+
|
|
From: Shigeharu T. <sh...@ie...> - 2011-10-07 03:46:01
|
shige 10/07 2011
----------------
I wrote:
| Ethan Merritt <merritt@u.washington.edu> wrote:
| | Some Googling suggests that VC++ may work if you do
| | #define snprintf _snprintf
| |
| | This would have to go in some header or configuration file,
| | along with HAVE_SNPRINTF.
|
| Thank you for your reply. But, we already use them (see
| config/config.nt).
I found that the function _snprintf(s, n, format, ...) of VC++
does:
1) if the length of the result string is larger than n, then
it copies n charcters to s and does not add '\0',
2) and then it sets errno to ERANGE.
The last behaver seems to be the reason the gnuplot says
"undefined value". The following patch for src/internal.c is the
dirty huck for this problem:
----- From here -----
--- internal.c~ Fri Oct 7 12:33:11 2011
+++ internal.c Fri Oct 7 12:35:29 2011
@@ -1312,6 +1312,10 @@
default:
int_error(NO_CARET,"internal error: invalid spec_type");
}
+#if MSVC
+ buffer[bufsize-1] = '\0'; /* shige : for safe for VC++ */
+ if (errno == ERANGE) errno = 0; /* shige : very dirty huck for VC++ */
+#endif
#endif
next_start[next_length] = tempchar;
----- To here -----
+========================================================+
Shigeharu TAKENO NIigata Institute of Technology
kashiwazaki,Niigata 945-1195 JAPAN
sh...@ie... TEL(&FAX): +81-257-22-8161
+========================================================+
|
|
From: Shigeharu T. <sh...@ie...> - 2011-10-07 03:58:45
|
shige 10/07 2011
----------------
I wrote:
| The last behaver seems to be the reason the gnuplot says
| "undefined value". The following patch for src/internal.c is the
| dirty huck for this problem:
|
| ----- From here -----
| --- internal.c~ Fri Oct 7 12:33:11 2011
| +++ internal.c Fri Oct 7 12:35:29 2011
| @@ -1312,6 +1312,10 @@
| default:
| int_error(NO_CARET,"internal error: invalid spec_type");
| }
| +#if MSVC
| + buffer[bufsize-1] = '\0'; /* shige : for safe for VC++ */
| + if (errno == ERANGE) errno = 0; /* shige : very dirty huck for VC++ */
| +#endif
| #endif
|
| next_start[next_length] = tempchar;
| ----- To here -----
Sorry, I made a mistake for the position. The following is
correct:
----- From here -----
--- internal.c~ Fri Oct 7 12:33:11 2011
+++ internal.c Fri Oct 7 12:54:38 2011
@@ -1297,6 +1297,10 @@
default:
int_error(NO_CARET,"internal error: invalid spec_type");
}
+#if VCPP
+ buffer[bufsize-1] = '\0'; /* shige : for safe for VC++ */
+ if (errno == ERANGE) errno = 0; /* shige : very dirty huck for VC++ */
+#endif
#else
/* FIXME - this is bad; we should dummy up an snprintf equivalent */
switch(spec_type) {
----- To here -----
+========================================================+
Shigeharu TAKENO NIigata Institute of Technology
kashiwazaki,Niigata 945-1195 JAPAN
sh...@ie... TEL(&FAX): +81-257-22-8161
+========================================================+
|