This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Possible error in cygpath


In cygpath.cc there is a function that goes like this:

static char *
get_short_name (const char *filename)
{
  char *sbuf;
  DWORD len = GetShortPathName (filename, NULL, 0);
  if (len == ERROR_INVALID_PARAMETER)
    {
      fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
	       filename);
      exit (2);
    }
  sbuf = (char *) malloc (++len);
  if (sbuf == NULL)
    {
      fprintf (stderr, "%s: out of memory\n", prog_name);
      exit (1);
    }
  if (GetShortPathName (filename, sbuf, len) == ERROR_INVALID_PARAMETER)
    {
      fprintf (stderr, "%s: cannot create short name of %s\n", prog_name,
	       filename);
      exit (2);
    }
  fprintf(stderr, "get_short_name: sbuf=%s\n",sbuf);
  return sbuf;
}


The spot where it says:
  DWORD len = GetShortPathName (filename, NULL, 0);
  if (len == ERROR_INVALID_PARAMETER)

is what worries me, I think it should be a little more like:
  DWORD len = GetShortPathName (filename, NULL, 0);
  if (len == 0 && GetLastError() == ERROR_INVALID_PARAMETER)

I don't know how this problem might manifest itself though I suspect that
if GetShortPathName returns a length of 87 then bad things might happen 
( 87 The parameter is incorrect. ERROR_INVALID_PARAMETER).

By the way I noticed this while I was trying to add a -l option to cygpath
which is similar to the -s option but it will convert a muddled 8.3 name
like PROGRA~1 to "Program Files" and I want to know if anyone else might
have been working on that.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]