Bug #24561 Run-time check failure #3 - The variable 'yylval' is used without being defined
Submitted: 23 Nov 2006 22:17 Modified: 21 Feb 2008 14:16
Reporter: Isabella Tan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Embedded Library ( libmysqld ) Severity:S2 (Serious)
Version:4.1.21 OS:Windows (Windows XP)
Assigned to: Alexey Botchkov CPU Architecture:Any
Tags: libmysqld, windows

[23 Nov 2006 22:17] Isabella Tan
Description:
When using libmysqld with my application, every time I call mysql_query() or mysql_stmt_prepare(), I get a warning saying "Run-time check failure #3 - The variable 'yylval' is used without being defined". This happens both within and out of the debug environment of Visual Studio .NET 2003.

The only work around would be to compile with a different run-time check level, but I feel that checking for uninitialized variables is important.

How to repeat:
In VS .NET 2003 debug environment, basic run-time checks set to "Both (/RTC1, equiv. to /RTCsu)" (i.e. both Stack Frames and Uninitialized Variables). Compile and run the following:

// MySQLEmbedTest.cpp : Defines the entry point for the console application.
/

#include "stdafx.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winsock.h>

#include "mysql.h"

MYSQL *mysql;
MYSQL_RES *results;
MYSQL_ROW record;

static char *server_args[] = {
		"MySQLEmbed",       /* this string is not used */
		"--defaults-file=/my.cnf"
};

int num_elements = sizeof(server_args)/ sizeof(char *);

static char *server_groups[] = {
  "embedded",
  "server",
  "MySQLEmbedTest_libmysqld_SERVER",
  (char *)NULL
};

int _tmain(int argc, _TCHAR* argv[])
{
   mysql_server_init(num_elements, server_args, server_groups);
   mysql = mysql_init(NULL);	
   
   mysql_options(mysql, 
		 MYSQL_READ_DEFAULT_GROUP, 
	         "libmysqld_client");

   mysql_options(mysql, 
                 MYSQL_OPT_USE_EMBEDDED_CONNECTION, 
                 NULL);

   mysql_real_connect(mysql, NULL,NULL,NULL, "TestDB", 0,NULL,0);

   mysql_query(mysql, "SELECT ClientID FROM Client");

   results = mysql_store_result(mysql);

   while((record = mysql_fetch_row(results))) {
      printf("%s - %s \n", record[0], record[1]);
   }

   mysql_free_result(results);
   mysql_close(mysql);
   mysql_server_end();

   return 0;
}
 
======================================================================

# my.cnf

[libmysqld_server]
datadir = C:/Test Site/MySQLEmbedTest/data/
language = C:/Test Site/MySQLEmbedTest/english
skip-innodb

[libmysqld_client]
language = C:/Test Site/MySQLEmbedTest/english

[MySQLEmbedTest_libmysqld_client]
language = C:/Test Site/MySQLEmbedTest/english

[MySQLEmbedTest_libmysqld_SERVER]
datadir = C:/Test Site/MySQLEmbedTest/data/
language = C:/Test Site/MySQLEmbedTest/english
skip-innodb

[embedded]
datadir = C:/Test Site/MySQLEmbedTest/data/
language = C:/Test Site/MySQLEmbedTest/english
skip-innodb

[server]
datadir = C:/Test Site/MySQLEmbedTest/data/
language = C:/Test Site/MySQLEmbedTest/english
skip-innodb 

Suggested fix:
Only work around I can think of is to compile with run-time check level not set to look for uninitialized variables, but this is not recommended.
[23 Nov 2006 22:21] Isabella Tan
Changed category
[24 Nov 2006 0:58] MySQL Verification Team
Thank you for the bug report. I tested your sample with VS2005 with some
modification to make more easy the test and I was unable to get what you
are reporting. I used the current source repository:

C:\mysql>bug24561
Connected to the server: 4.1.23-embedded-debug
localhost - (null)
localhost - (null)

// MySQLEmbedTest.cpp : Defines the entry point for the console application.

//#include "stdafx.h"

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <winsock.h>

#include "mysql.h"

MYSQL *mysql;
MYSQL_RES *results;
MYSQL_ROW record;

static char *server_args[] = {
		"MySQLEmbed",       /* this string is not used */
		"--defaults-file=/my.cnf"
};

int num_elements = sizeof(server_args)/ sizeof(char *);

static char *server_groups[] = {
  "embedded",
  "server",
  "MySQLEmbedTest_libmysqld_SERVER",
  (char *)NULL
};

int main(int argc, char* argv[])
{
   mysql_server_init(num_elements, server_args, server_groups);
   mysql = mysql_init(NULL);	
   
   mysql_options(mysql, 
		 MYSQL_READ_DEFAULT_GROUP, 
	         "libmysqld_client");

   mysql_options(mysql, 
                 MYSQL_OPT_USE_EMBEDDED_CONNECTION, 
                 NULL);

   mysql_real_connect(mysql, "localhost","root","", "mysql", 0,NULL,0);

   printf("Connected to the server: %s\n",mysql_get_server_info(mysql));

   mysql_query(mysql, "SELECT Host FROM user");

   results = mysql_store_result(mysql);

   while((record = mysql_fetch_row(results))) {
      printf("%s - %s \n", record[0], record[1]);
   }

   mysql_free_result(results);
   mysql_close(mysql);
   mysql_server_end();

   return 0;
}
[24 Nov 2006 1:32] Isabella Tan
Hi Miguel,

Thanks so much for your prompt reply! I am unable to find 4.1.23 version, would you please kindly refer me to the appropriate download site?

Thank you so much!

Kind regards,
Isabella
[24 Nov 2006 1:43] Isabella Tan
Running your modified example, I get the following output:

C:\Test Site\MySQLEmbedCTest\Debug>MySQLEmbedCTest.exe
Connected to the server: 4.1.21-community-debug-embedded
localhost - (null)
localhost - (null)

I am still getting the same message, but the program continues normally after I click 'Ignore' on the error message dialog.

Thanks again for your assistance!!
[24 Nov 2006 11:33] MySQL Verification Team
Hello,

We don't have to download a source package for today source repository, you need
instead to do the instructions mentioned in the Manual:

2.9.6.2. Creating a Windows Source Package from the Latest Development Source
http://dev.mysql.com/doc/refman/4.1/en/windows-bitkeeper-build.html
[27 Nov 2006 21:03] Isabella Tan
Thanks Miguel,

I tried downloading the source for 4.1.23, but have been unsuccessful with creating a Windows package from the source. I followed all the instructions in http://dev.mysql.com/doc/refman/4.1/en/installing-source-tree.html (configure options CC=gcc and CXX=gcc, with embedded server), and also on http://dev.mysql.com/doc/refman/4.1/en/windows-bitkeeper-build.html. I've attempted to 'uninstall' and rebuild multiple times, but none have worked. Without building from the complete-pentium-max, I was able to run the script for the windows package but it gave me the following error:

make: Entering directory `/cygdrive/c/mysql-source/mysql-4.1/ndb'
make: *** No rule to make target `windoze'.  Stop.
make: Leaving directory `/cygdrive/c/mysql-source/mysql-4.1/ndb'
cp: cannot create regular file `/cygdrive/c/DOCUME~1/Isabella/LOCALS~1/Temp/my_w
in_dist.3928/bdb/build_win32/libdb_tcl.def': Permission denied
*** script failed ***

On the other hand, after building from complete-pentium-max, I was unable to even start the shell script (it wouldn't start unless I put the .sh extension, and when I did it returned the following: "You must run this script from the MySQL top-level directory" even when I did run in from the top directory)

I tried running the sample on Visual Studio 2005 .NET on another computer and got the same runtime check failure, thus I'm assuming the 4.1.23 embedded server would not have the same problem (as you were unable to repeat it). 

Thanks for your help, I think I should be heading to the forums now... ;-)

Kind regards,
Isabella
[27 Nov 2006 21:28] MySQL Verification Team
Hi,

Assuming you have created the mysql-4.1 clone on your Linux box, then
compile it using the below script:

miguel@hegel:~/dbs/mysql-4.1> BUILD/compile-pentium-debug-max

after you have compiled create the source package issuing:

miguel@hegel:~/dbs/mysql-4.1> scripts/make_win_src_distribution 

then the below file is created:

miguel@hegel:~/dbs/mysql-4.1> ls *.zip
mysql-4.1.23-win-src.zip

Just to clarify I was able to repeat your test case with the embedded
server version 4.1.21 from the release package, however I was unable
to repeat with embedded server I compiled myself from the source.
[27 Nov 2006 21:56] Isabella Tan
Hi Miguel,

Thanks again! I'm using cygwin on windows (as I do not have Linux installed), and did the following:

- downloaded 4.1 source using bitkeeper 
- went to mysql 4.1/ directory and compiled using: 
$ BUILD/compile-pentium-debug-max

I got the following error in the end:
...
configure: creating ./config.status
config.status: creating Makefile
config.status: creating db_cxx.h
config.status: creating db_int.h
config.status: creating include.tcl
config.status: creating db.h
config.status: creating db_config.h
END OF BERKELEY DB CONFIGURATION
Including ndb shared memory transporter
configure: creating ./config.status
config.status: creating libmysql/libmysql.ver
config.status: error: cannot find input file: tools/Makefile.in

When I went into the directory, only these files where there:
Isabella@hearlab1 /cygdrive/c/mysql-source/mysql-4.1/tools
$ ls
Makefile.am  managertest1.nc  mysqlmanager-sample.pwd  mysqlmanager.c

I made sure I had the most up-to-date GNU software (as required shown in the documentation), but I may have missed something?

Thanks,
Isabella
[29 Nov 2006 0:28] Isabella Tan
Hi Miguel,

I downloaded the latest release of the 4.1.22 server from MySQL website, and built the embedded server from the source code. I made the following change to sql_yacc.cpp, line 12166 in order to rid the run-time check failure error:

================================================================================

    /* The semantic value of the look-ahead symbol.  */
    YYSTYPE yylval;
    yylval.num = 0; // I added this line to initialise yylval
    ...
    yyvsp[0] = yylval; // this was where run-time check failure occurred before

================================================================================

During build, the following warning was issued before I added the initialization:

"c:\mysql-source\mysql-4.1.22\libmysqld\sql_yacc.cc(12228) : warning C4700: local variable 'yylval' used without having been initialized"

I am unsure whether what I did is the best way to go around the issue though, so I'll be waiting for the 4.1.23 release :) (unfortunately i have been unable to compile the package from source repository even on a linux box)

Kind regards,
Isabella
[9 Jan 2007 19:42] MySQL Verification Team
I got that error messages while testing the bug: http://bugs.mysql.com/bug.php?id=25492 when trying to load
the embedded server 4.1.22 from our release package to
application debug version compiled with VS 2005 Pro, so
I am changing the status to verified.

Thank you for the feedback.
[18 Feb 2008 14:56] Alexey Botchkov
It looks like it's a problem of Bison 1.8 and probably earlier versions.
I wasn't able to repeat this bug with Bison 2.1, and cannot repeat it with the latest source distribution as well.

So i'd recommend to warn people against old Bison-s and to recommend new sources to these affected.
[21 Feb 2008 14:16] Paul DuBois
The manual has comments on bison versions on this page:
http://dev.mysql.com/doc/refman/4.1/en/installing-source-tree.html

"To configure MySQL 4.1, you also need GNU bison. You should use the latest version of bison where possible. Version 1.75 and version 2.1 are known to work. There have been reported problems with bison 1.875. If you experience problems, upgrade to a later, rather than earlier, version. Versions of bison older than 1.75 may report this error:

sql_yacc.yy:#####: fatal error: maximum table size (32767) exceeded
Note: The maximum table size is not actually exceeded; the error is caused by bugs in older versions of bison."

That seems to cover the present case.