Subject: patch 5.4.3 (was: Bug#42005: SEGV when using Python hooks)
From: Bram Moolenaar <[email-masked]>
To: Wichert Akkerman <[email-masked]>
Cc: VIM Development List <[email-masked]>

------------

Wichert Akkerman wrote:

> I got this bugreport yesterday through the Debian Bugtracking system.
> Since I don't use (or know) python myself I can't help him..
> 
> Can anyone reproduce this?

Yes.  Easy to spot the problem with "ddd".

[...]
>   Executing the following two commands when an unnamed file is loaded into
> buffer 0 causes vim to segv.  If I understand the documentation correctly,
> it should print out the repr of the 0th buffer.  Accessing members of
> vim.buffers[0] works correctly and loading a file, then printing
> vim.buffers[0] works correctly.
> 
> :python import vim
> :python print vim.buffers[0]

Patch 5.4.3
Problem:    Python: Trying to use the name of an unnamed buffer caused a 
            crash. (Daniel Burrows)
Solution:   Check for b_fname being a NULL pointer.
Files:      src/if_python.c

*** ../vim-5.4/src/if_python.c	Sun Jul 25 22:02:15 1999
--- src/if_python.c	Wed Jul 28 15:55:29 1999
***************
*** 951,957 ****
      else
      {
  	char *name = (char *)this->buf->b_fname;
! 	int len = strlen(name);
  
  	if (len > 35)
  	    name = name + (35 - len);
--- 951,961 ----
      else
      {
  	char *name = (char *)this->buf->b_fname;
! 	int len;
! 
! 	if (name == NULL)
! 	    name = "";
! 	len = strlen(name);
  
  	if (len > 35)
  	    name = name + (35 - len);
***************
*** 1162,1168 ****
      else
      {
  	char *name = (char *)this->buf->buf->b_fname;
! 	int len = strlen(name);
  
  	if (len > 45)
  	    name = name + (45 - len);
--- 1166,1176 ----
      else
      {
  	char *name = (char *)this->buf->buf->b_fname;
! 	int len;
! 
! 	if (name == NULL)
! 	    name = "";
! 	len = strlen(name);
  
  	if (len > 45)
  	    name = name + (45 - len);
*** /tmp/version.h	Wed Jul 28 16:00:56 1999
--- src/version.h	Wed Jul 28 16:01:19 1999
***************
*** 19,26 ****
  #define VIM_VERSION_MINOR_STR		"4"
  #define VIM_VERSION_BUILD		 57
  #define VIM_VERSION_BUILD_STR		"57"
! #define VIM_VERSION_PATCHLEVEL		 2
! #define VIM_VERSION_PATCHLEVEL_STR	"2"
  
  /*
   * VIM_VERSION_NODOT is used for the runtime directory name.
--- 19,26 ----
  #define VIM_VERSION_MINOR_STR		"4"
  #define VIM_VERSION_BUILD		 57
  #define VIM_VERSION_BUILD_STR		"57"
! #define VIM_VERSION_PATCHLEVEL		 3
! #define VIM_VERSION_PATCHLEVEL_STR	"3"
  
  /*
   * VIM_VERSION_NODOT is used for the runtime directory name.
***************
*** 30,35 ****
   */
  #define VIM_VERSION_NODOT	"vim54"
  #define VIM_VERSION_SHORT	"5.4"
! #define VIM_VERSION_MEDIUM	"5.4.2"
! #define VIM_VERSION_LONG	"VIM - Vi IMproved 5.4.2 (1999 Jul 27)"
! #define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 5.4.2 (1999 Jul 27, compiled "
--- 30,35 ----
   */
  #define VIM_VERSION_NODOT	"vim54"
  #define VIM_VERSION_SHORT	"5.4"
! #define VIM_VERSION_MEDIUM	"5.4.3"
! #define VIM_VERSION_LONG	"VIM - Vi IMproved 5.4.3 (1999 Jul 28)"
! #define VIM_VERSION_LONG_DATE	"VIM - Vi IMproved 5.4.3 (1999 Jul 28, compiled "

--
CONCORDE: Message for you, sir.
   He falls forward revealing the arrow with the note.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

--/-/---- Bram Moolenaar ---- [email-masked] ---- [email-masked] ---\-\--
  \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /