mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Fix a crash when completing sessions, from Anindya Mukherjee.
This commit is contained in:
		
							
								
								
									
										19
									
								
								status.c
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								status.c
									
									
									
									
									
								
							@@ -1441,6 +1441,8 @@ status_prompt_complete_prefix(char **list, u_int size)
 | 
			
		||||
	u_int	  i;
 | 
			
		||||
	size_t	  j;
 | 
			
		||||
 | 
			
		||||
	if (list == NULL || size == 0)
 | 
			
		||||
		return (NULL);
 | 
			
		||||
	out = xstrdup(list[0]);
 | 
			
		||||
	for (i = 1; i < size; i++) {
 | 
			
		||||
		j = strlen(list[i]);
 | 
			
		||||
@@ -1649,13 +1651,22 @@ status_prompt_complete_session(char ***list, u_int *size, const char *s,
 | 
			
		||||
    char flag)
 | 
			
		||||
{
 | 
			
		||||
	struct session	*loop;
 | 
			
		||||
	char		*out, *tmp;
 | 
			
		||||
	char		*out, *tmp, n[11];
 | 
			
		||||
 | 
			
		||||
	RB_FOREACH(loop, sessions, &sessions) {
 | 
			
		||||
		if (*s != '\0' && strncmp(loop->name, s, strlen(s)) != 0)
 | 
			
		||||
			continue;
 | 
			
		||||
		*list = xreallocarray(*list, (*size) + 2, sizeof **list);
 | 
			
		||||
		if (*s == '\0' || strncmp(loop->name, s, strlen(s)) == 0) {
 | 
			
		||||
			*list = xreallocarray(*list, (*size) + 2,
 | 
			
		||||
			    sizeof **list);
 | 
			
		||||
			xasprintf(&(*list)[(*size)++], "%s:", loop->name);
 | 
			
		||||
		} else if (*s == '$') {
 | 
			
		||||
			xsnprintf(n, sizeof n, "%u", loop->id);
 | 
			
		||||
			if (s[1] == '\0' ||
 | 
			
		||||
			    strncmp(n, s + 1, strlen(s) - 1) == 0) {
 | 
			
		||||
				*list = xreallocarray(*list, (*size) + 2,
 | 
			
		||||
				    sizeof **list);
 | 
			
		||||
				xasprintf(&(*list)[(*size)++], "$%s:", n);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	out = status_prompt_complete_prefix(*list, *size);
 | 
			
		||||
	if (out != NULL && flag != '\0') {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user