Bug #24730 Wrong embedded server example
Submitted: 30 Nov 2006 18:05 Modified: 30 Nov 2006 19:37
Reporter: Sveta Smirnova Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:4.1, 5.1 OS:Any (any)
Assigned to: Paul Dubois CPU Architecture:Any

[30 Nov 2006 18:05] Sveta Smirnova
Description:
Embedded server example 1 (http://dev.mysql.com/doc/refman/4.1/en/libmysqld-example.html, http://dev.mysql.com/doc/refman/5.1/en/libmysqld-example.html) contains mistake:

static char *server_options[] = { "mysql_test", "--defaults-file=my.cnf", NULL };
int num_elements = sizeof(server_options)/ sizeof(char *);

If one compiles and runs example program [s]he will gets segmentation fault.

How to repeat:
Try to compile and run example 1.

Suggested fix:
static char *server_options[] = { "mysql_test", "--defaults-file=my.cnf", NULL };
int num_elements = 2;
[30 Nov 2006 18:56] Paul Dubois
Sveta, rather than hard-coding 2 into the example, would
it be better to do this:

int num_elements = (sizeof(server_options)/ sizeof(char *)) - 1;

Does that work?
[30 Nov 2006 19:19] Sveta Smirnova
Paul, yes, it would be fine.
[30 Nov 2006 19:37] Paul Dubois
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.