Moving my OS/2 setup to PDCurses 2.6 recently, I found a bug that crashed
my application almost immediately (and repeatably), which I traced to
PDC_query_adapter_type(). In 2.6, it looks like this:


/***********************************************************************/
#if defined(EMXVIDEO)
int PDC_query_adapter_type( void )
#else
int PDC_query_adapter_type( VIOCONFIGINFO *configinfo )
#endif
/***********************************************************************/
{
#ifndef EMXVIDEO
   VIOCONFIGINFO aconfiginfo;
#else
   int retval = _NONE;
#endif
#ifdef PDCDEBUG
   if (trace_on) PDC_debug("PDC_query_adapter_type() - called\n");
#endif
#ifdef EMXVIDEO
   if (v_hardware() == V_MONOCHROME)
      retval = _UNIX_MONO;
   else
      retval = _UNIX_COLOR;
   return(retval);
#else
   VioGetConfig( 0, &aconfiginfo, 0 );
   *configinfo = aconfiginfo;
   return(OK);
#endif
}


The problem is that, apparently, VioGetConfig() doesn't completely fill
the VIOCONFIGINFO structure with data; so some junk may be left in the
structure after the call. If the structure is first initialized to all 0's
(as it was in 2.5), everything works fine.

One could add a memset() call before VioGetConfig() to ensure this; but in
this case, the simplest fix is to eliminate the redundant copy
("*configinfo = aconfiginfo") and pass the configinfo pointer directly to
VioGetConfig(). The structure that's passed to PDC_query_adapter_type()
has already been zeroed out by this point, as part of the SP structure. To
be fully safe, perhaps there should still be a memset(), but that means
adding another dependency to pdcgetsc.c, so I haven't bothered.

So, my revised version looks like this:


/***********************************************************************/
#if defined(EMXVIDEO)
int PDC_query_adapter_type( void )
#else
int PDC_query_adapter_type( VIOCONFIGINFO *configinfo )
#endif
/***********************************************************************/
{
#ifdef EMXVIDEO
   int retval = _NONE;
#endif
#ifdef PDCDEBUG
   if (trace_on) PDC_debug("PDC_query_adapter_type() - called\n");
#endif
#ifdef EMXVIDEO
   if (v_hardware() == V_MONOCHROME)
      retval = _UNIX_MONO;
   else
      retval = _UNIX_COLOR;
   return(retval);
#else
   VioGetConfig( 0, configinfo, 0 );
   return(OK);
#endif


Patch attached.

-- 
William McBrine <[EMAIL PROTECTED]>
*** os2/pdcgetsc.c.old  Fri Jan 11 23:05:11 2002
--- os2/pdcgetsc.c      Fri May 23 16:34:45 2003
***************
*** 474,482 ****
  #endif
  /***********************************************************************/
  {
! #ifndef EMXVIDEO
!    VIOCONFIGINFO aconfiginfo;
! #else
     int retval = _NONE;
  #endif
  #ifdef PDCDEBUG
--- 474,480 ----
  #endif
  /***********************************************************************/
  {
! #ifdef EMXVIDEO
     int retval = _NONE;
  #endif
  #ifdef PDCDEBUG
***************
*** 489,496 ****
        retval = _UNIX_COLOR;
     return(retval);
  #else
!    VioGetConfig( 0, &aconfiginfo, 0 );
!    *configinfo = aconfiginfo;
     return(OK);
  #endif
  }
--- 487,493 ----
        retval = _UNIX_COLOR;
     return(retval);
  #else
!    VioGetConfig( 0, configinfo, 0 );
     return(OK);
  #endif
  }

Reply via email to