Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Long directories in prompt



%~, %d, %c, %. and %C prompt escapes caused coredump when pwd was longer
than PATH_MAX.

This patch fixes putpromptchar() but still there is a bug in finddir()
causing coredumps when %~ is used.

This is for zsh-3.1.0 only.

Zoltan


*** Src/prompt.c	1996/12/21 02:35:32	3.1.1.0
--- Src/prompt.c	1996/12/30 03:20:14
***************
*** 293,300 ****
  	    switch (*fm) {
  	    case '~':
  		if ((nd = finddir(pwd))) {
! 		    sprintf(buf3, "~%s%s", nd->nam, pwd + strlen(nd->dir));
! 		    stradd(buf3);
  		    break;
  		}
  	    case 'd':
--- 293,301 ----
  	    switch (*fm) {
  	    case '~':
  		if ((nd = finddir(pwd))) {
! 		    stradd("~");
! 		    stradd(nd->nam);
! 		    stradd(pwd + strlen(nd->dir));
  		    break;
  		}
  	    case 'd':
***************
*** 303,333 ****
  		break;
  	    case 'c':
  	    case '.':
! 		if ((nd = finddir(pwd)))
! 		    sprintf(buf3, "~%s%s", nd->nam, pwd + strlen(nd->dir));
! 		else
! 		    strcpy(buf3, pwd);
! 		if (!arg)
! 		    arg++;
! 		for (ss = buf3 + strlen(buf3); ss > buf3; ss--)
! 		    if (*ss == '/' && !--arg) {
  			ss++;
! 			break;
! 		    }
! 		if (*ss == '/' && ss[1] && (ss != buf3))
! 		    ss++;
! 		stradd(ss);
! 		break;
  	    case 'C':
- 		strcpy(buf3, pwd);
  		if (!arg)
  		    arg++;
! 		for (ss = buf3 + strlen(buf3); ss > buf3; ss--)
  		    if (*ss == '/' && !--arg) {
  			ss++;
  			break;
  		    }
! 		if (*ss == '/' && ss[1] && (ss != buf3))
  		    ss++;
  		stradd(ss);
  		break;
--- 304,340 ----
  		break;
  	    case 'c':
  	    case '.':
! 	        {
! 		    char *t;
! 
! 		    if ((nd = finddir(pwd)))
! 			t = pwd + strlen(nd->dir);
! 		    else
! 			t = pwd;
! 		    if (!arg)
! 			arg++;
! 		    for (ss = t + strlen(t); ss > t; ss--)
! 			if (*ss == '/' && !--arg) {
! 			    ss++;
! 			    break;
! 			}
! 		    if (nd && ss == t && (*ss != '/' || arg > 1)) {
! 			stradd("~");
! 			stradd(nd->nam);
! 		    } else if (*ss == '/' && ss[1] && (ss != pwd))
  			ss++;
! 		    stradd(ss);
! 		    break;
! 		}
  	    case 'C':
  		if (!arg)
  		    arg++;
! 		for (ss = pwd + strlen(pwd); ss > pwd; ss--)
  		    if (*ss == '/' && !--arg) {
  			ss++;
  			break;
  		    }
! 		if (*ss == '/' && ss[1] && (ss != pwd))
  		    ss++;
  		stradd(ss);
  		break;



Messages sorted by: Reverse Date, Date, Thread, Author