> Your solution depends on strtok() changing the space after the command to
> a NUL.  What if there are several spaces:  ":cs find   e a"?  I don't
> think it is defined what strtok() does with the extra spaces.  They
> could be replaced with NUL or not.
>
> Another solution, which is not clean either, is to store the length of
> eap->arg in a global variable, before the first call to strtok().

Yes. That assumption bothered me a bit too. Changing eap->arg
after call to strtok(eap->arg, " ") may be asking for trouble.  But
information is just missing in cs_find() to implement a fix without
either:
- passing an extra parameter to the function (but it's used
  as function pointer, so we'd need to change other functions
  too (so I don't like it)
- adding a field in exarg_T with length of eap->arg, but type
  is used in tons of other places (so I don't like it)
- using a global static variable as you suggest to store length
  of eap->arg (maybe not clean, but most pragmatic solution)

So I attach a patch which uses a global static variable.
It is more portable and also simpler than my previous patch.

-- Dominique

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Index: if_cscope.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/if_cscope.c,v
retrieving revision 1.22
diff -c -r1.22 if_cscope.c
*** if_cscope.c 11 Mar 2007 14:48:29 -0000      1.22
--- if_cscope.c 19 Aug 2007 15:35:11 -0000
***************
*** 71,77 ****
  static char *     cs_resolve_file __ARGS((int, char *));
  static int        cs_show __ARGS((exarg_T *eap));
  
! 
  static csinfo_T           csinfo[CSCOPE_MAX_CONNECTIONS];
  static cscmd_T            cs_cmds[] =
  {
--- 71,77 ----
  static char *     cs_resolve_file __ARGS((int, char *));
  static int        cs_show __ARGS((exarg_T *eap));
  
! static int        len_eap_arg;    /* store length of eap->arg */
  static csinfo_T           csinfo[CSCOPE_MAX_CONNECTIONS];
  static cscmd_T            cs_cmds[] =
  {
***************
*** 386,392 ****
   * PRIVATE: cs_add
   *
   * add cscope database or a directory name (to look for cscope.out)
!  * the the cscope connection list
   *
   * MAXPATHL 256
   */
--- 386,392 ----
   * PRIVATE: cs_add
   *
   * add cscope database or a directory name (to look for cscope.out)
!  * to the cscope connection list
   *
   * MAXPATHL 256
   */
***************
*** 966,972 ****
      }
  
      pat = opt + strlen(opt) + 1;
!     if (pat == NULL || (pat != NULL && pat[0] == '\0'))
      {
        cs_usage_msg(Find);
        return FALSE;
--- 966,972 ----
      }
  
      pat = opt + strlen(opt) + 1;
!     if (pat >= (char *)eap->arg + len_eap_arg)
      {
        cs_usage_msg(Find);
        return FALSE;
***************
*** 1317,1323 ****
  #else
            /* compare pathnames first */
            && ((fullpathcmp(csinfo[j].fname, fname, FALSE) & FPC_SAME)
!               /* if not Windows 9x, test index file atributes too */
                || (!mch_windows95()
                    && csinfo[j].nVolume == bhfi.dwVolumeSerialNumber
                    && csinfo[j].nIndexHigh == bhfi.nFileIndexHigh
--- 1317,1323 ----
  #else
            /* compare pathnames first */
            && ((fullpathcmp(csinfo[j].fname, fname, FALSE) & FPC_SAME)
!               /* if not Windows 9x, test index file attributes too */
                || (!mch_windows95()
                    && csinfo[j].nVolume == bhfi.dwVolumeSerialNumber
                    && csinfo[j].nIndexHigh == bhfi.nFileIndexHigh
***************
*** 1401,1406 ****
--- 1401,1408 ----
      if (eap->arg == NULL)
        return NULL;
  
+     /* Store length of eap->arg before it gets modified by strtok() */
+     len_eap_arg = STRLEN(eap->arg);
      if ((stok = strtok((char *)(eap->arg), (const char *)" ")) == NULL)
        return NULL;
  
***************
*** 2195,2201 ****
            cs_add_common(dblist[i], pplist[i], fllist[i]);
            if (p_csverbose)
            {
!               /* dont' use smsg_attr because want to display
                 * connection number in the same line as
                 * "Added cscope database..."
                 */
--- 2197,2203 ----
            cs_add_common(dblist[i], pplist[i], fllist[i]);
            if (p_csverbose)
            {
!               /* don't use smsg_attr because want to display
                 * connection number in the same line as
                 * "Added cscope database..."
                 */

Reply via email to