Bug #25378 Compiler warning from assigning -1 to a uint
Submitted: 3 Jan 2007 1:31 Modified: 3 Jan 2007 11:57
Reporter: Mark Callaghan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:5.0.30 OS:Linux (Linux 2.4)
Assigned to: CPU Architecture:Any
Tags: compiler, warning

[3 Jan 2007 1:31] Mark Callaghan
Description:
'key_nr=-1' below generates a compiler warning. key_nr has type uint

void handler::print_error(int error, myf errflag)
{
  <snip>
  int textno=ER_GET_ERRNO;
  switch (error) {
  case EACCES:
    textno=ER_OPEN_AS_READONLY;
    break;
  <snip>
  case HA_ERR_FOUND_DUPP_KEY:
  {
    uint key_nr=get_dup_key(error);
    if ((int) key_nr >= 0)
    {
      /* Write the dupplicated key in the error message */
      char key[MAX_KEY_LENGTH];
      String str(key,sizeof(key),system_charset_info);

      if (key_nr == MAX_KEY)
      {
        /* Key is unknown */
        str.copy("", 0, system_charset_info);
        key_nr= -1;

How to repeat:
compile handler.cc

Suggested fix:
Make it an int, or cast -1 to uint
[3 Jan 2007 11:57] Valeriy Kravchuk
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release. In current 5.0.34-Bk we have:

void handler::print_error(int error, myf errflag)
{
...

  case HA_ERR_FOUND_DUPP_KEY:
  {
    uint key_nr=get_dup_key(error);
    if ((int) key_nr >= 0)
    {
      /* Write the dupplicated key in the error message */
      char key[MAX_KEY_LENGTH];
      String str(key,sizeof(key),system_charset_info);

      if (key_nr == MAX_KEY)
      {
        /* Key is unknown */
        str.copy("", 0, system_charset_info);
        key_nr= (uint) -1;
      }
      else
      {
        key_unpack(&str,table,(uint) key_nr);
...

exactly as you suggested.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html