comparison src/if_cscope.c @ 4581:6a73ac422c67 v7.3.1038

updated for version 7.3.1038 Problem: Crash when using Cscope. Solution: Avoid negative argument to vim_strncpy(). (Narendran Gopalakrishnan)
author Bram Moolenaar <bram@vim.org>
date Wed, 29 May 2013 19:18:00 +0200
parents 04736b4030ec
children 04b8912a9c85
comparison
equal deleted inserted replaced
4580:aaf7060868eb 4581:6a73ac422c67
2458 2458
2459 2459
2460 /* 2460 /*
2461 * PRIVATE: cs_resolve_file 2461 * PRIVATE: cs_resolve_file
2462 * 2462 *
2463 * construct the full pathname to a file found in the cscope database. 2463 * Construct the full pathname to a file found in the cscope database.
2464 * (Prepends ppath, if there is one and if it's not already prepended, 2464 * (Prepends ppath, if there is one and if it's not already prepended,
2465 * otherwise just uses the name found.) 2465 * otherwise just uses the name found.)
2466 * 2466 *
2467 * we need to prepend the prefix because on some cscope's (e.g., the one that 2467 * We need to prepend the prefix because on some cscope's (e.g., the one that
2468 * ships with Solaris 2.6), the output never has the prefix prepended. 2468 * ships with Solaris 2.6), the output never has the prefix prepended.
2469 * contrast this with my development system (Digital Unix), which does. 2469 * Contrast this with my development system (Digital Unix), which does.
2470 */ 2470 */
2471 static char * 2471 static char *
2472 cs_resolve_file(i, name) 2472 cs_resolve_file(i, name)
2473 int i; 2473 int i;
2474 char *name; 2474 char *name;
2491 * path in path resolution. */ 2491 * path in path resolution. */
2492 csdir = alloc(MAXPATHL); 2492 csdir = alloc(MAXPATHL);
2493 if (csdir != NULL) 2493 if (csdir != NULL)
2494 { 2494 {
2495 vim_strncpy(csdir, (char_u *)csinfo[i].fname, 2495 vim_strncpy(csdir, (char_u *)csinfo[i].fname,
2496 gettail((char_u *)csinfo[i].fname) - 1 - (char_u *)csinfo[i].fname); 2496 gettail((char_u *)csinfo[i].fname)
2497 - (char_u *)csinfo[i].fname);
2497 len += (int)STRLEN(csdir); 2498 len += (int)STRLEN(csdir);
2498 } 2499 }
2499 } 2500 }
2500
2501 if ((fullname = (char *)alloc(len)) == NULL)
2502 return NULL;
2503 2501
2504 /* Note/example: this won't work if the cscope output already starts 2502 /* Note/example: this won't work if the cscope output already starts
2505 * "../.." and the prefix path is also "../..". if something like this 2503 * "../.." and the prefix path is also "../..". if something like this
2506 * happens, you are screwed up and need to fix how you're using cscope. */ 2504 * happens, you are screwed up and need to fix how you're using cscope. */
2507 if (csinfo[i].ppath != NULL 2505 if (csinfo[i].ppath != NULL
2509 && (name[0] != '/') 2507 && (name[0] != '/')
2510 #ifdef WIN32 2508 #ifdef WIN32
2511 && name[0] != '\\' && name[1] != ':' 2509 && name[0] != '\\' && name[1] != ':'
2512 #endif 2510 #endif
2513 ) 2511 )
2514 (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name); 2512 {
2515 else if (csdir != NULL && csinfo[i].fname != NULL && STRLEN(csdir) > 0) 2513 if ((fullname = (char *)alloc(len)) != NULL)
2514 (void)sprintf(fullname, "%s/%s", csinfo[i].ppath, name);
2515 }
2516 else if (csdir != NULL && csinfo[i].fname != NULL && *csdir != NUL)
2516 { 2517 {
2517 /* Check for csdir to be non empty to avoid empty path concatenated to 2518 /* Check for csdir to be non empty to avoid empty path concatenated to
2518 * cscope output. TODO: avoid the unnecessary alloc/free of fullname. */ 2519 * cscope output. */
2519 vim_free(fullname);
2520 fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE); 2520 fullname = (char *)concat_fnames(csdir, (char_u *)name, TRUE);
2521 } 2521 }
2522 else 2522 else
2523 (void)sprintf(fullname, "%s", name); 2523 {
2524 fullname = (char *)vim_strsave((char_u *)name);
2525 }
2524 2526
2525 vim_free(csdir); 2527 vim_free(csdir);
2526 return fullname; 2528 return fullname;
2527 } 2529 }
2528 2530