@@ -388,7 +388,7 @@ get_vim_env(void)
388388
389389 /* First get $VIMRUNTIME. If it's set, remove the tail. */
390390 vim = getenv ("VIMRUNTIME" );
391- if (vim != NULL && * vim != 0 && strlen (vim ) < BUFSIZE )
391+ if (vim != NULL && * vim != 0 && strlen (vim ) < sizeof ( buf ) )
392392 {
393393 strcpy (buf , vim );
394394 remove_tail (buf );
@@ -411,7 +411,7 @@ get_vim_env(void)
411411
412412 /* NSIS also uses GetTempPath(), thus we should get the same directory
413413 * name as where NSIS will look for vimini.ini. */
414- GetTempPath (BUFSIZE , fname );
414+ GetTempPath (sizeof ( fname ) - 12 , fname );
415415 add_pathsep (fname );
416416 strcat (fname , "vimini.ini" );
417417
@@ -456,7 +456,7 @@ window_cb(HWND hwnd, LPARAM lparam)
456456 static int
457457run_silent_uninstall (char * uninst_exe )
458458{
459- char vimrt_dir [MAX_PATH ];
459+ char vimrt_dir [BUFSIZE ];
460460 char temp_uninst [BUFSIZE ];
461461 char temp_dir [MAX_PATH ];
462462 char buf [BUFSIZE * 2 + 10 ];
@@ -506,7 +506,7 @@ uninstall_check(int skip_question)
506506 char * uninstall_key = "software\\Microsoft\\Windows\\CurrentVersion\\Uninstall" ;
507507 char subkey_name_buff [BUFSIZE ];
508508 char temp_string_buffer [BUFSIZE - 2 ];
509- DWORD local_bufsize = BUFSIZE ;
509+ DWORD local_bufsize ;
510510 FILETIME temp_pfiletime ;
511511 DWORD key_index ;
512512 char input ;
@@ -521,12 +521,14 @@ uninstall_check(int skip_question)
521521 KEY_WOW64_64KEY | KEY_READ , & key_handle );
522522 CHECK_REG_ERROR (code );
523523
524- for (key_index = 0 ;
525- RegEnumKeyEx (key_handle , key_index , subkey_name_buff , & local_bufsize ,
526- NULL , NULL , NULL , & temp_pfiletime ) != ERROR_NO_MORE_ITEMS ;
527- key_index ++ )
524+ key_index = 0 ;
525+ while (TRUE)
528526 {
529- local_bufsize = BUFSIZE ;
527+ local_bufsize = sizeof (subkey_name_buff );
528+ if (RegEnumKeyEx (key_handle , key_index , subkey_name_buff , & local_bufsize ,
529+ NULL , NULL , NULL , & temp_pfiletime ) == ERROR_NO_MORE_ITEMS )
530+ break ;
531+
530532 if (strncmp ("Vim" , subkey_name_buff , 3 ) == 0 )
531533 {
532534 /* Open the key named Vim* */
@@ -535,10 +537,10 @@ uninstall_check(int skip_question)
535537 CHECK_REG_ERROR (code );
536538
537539 /* get the DisplayName out of it to show the user */
540+ local_bufsize = sizeof (temp_string_buffer );
538541 code = RegQueryValueEx (uninstall_key_handle , "displayname" , 0 ,
539542 & value_type , (LPBYTE )temp_string_buffer ,
540543 & local_bufsize );
541- local_bufsize = BUFSIZE ;
542544 CHECK_REG_ERROR (code );
543545
544546 allow_silent = 0 ;
@@ -568,9 +570,9 @@ uninstall_check(int skip_question)
568570 fflush (stdout );
569571
570572 /* get the UninstallString */
573+ local_bufsize = sizeof (temp_string_buffer );
571574 code = RegQueryValueEx (uninstall_key_handle , "uninstallstring" , 0 ,
572575 & value_type , (LPBYTE )temp_string_buffer , & local_bufsize );
573- local_bufsize = BUFSIZE ;
574576 CHECK_REG_ERROR (code );
575577
576578 /* Remember the directory, it is used as the default for NSIS. */
@@ -683,6 +685,8 @@ uninstall_check(int skip_question)
683685
684686 RegCloseKey (uninstall_key_handle );
685687 }
688+
689+ key_index ++ ;
686690 }
687691 RegCloseKey (key_handle );
688692
@@ -1826,7 +1830,7 @@ create_shortcut(
18261830 /* translate the (possibly) multibyte shortcut filename to windows
18271831 * Unicode so it can be used as a file name.
18281832 */
1829- MultiByteToWideChar (CP_ACP , 0 , shortcut_name , -1 , wsz , BUFSIZE );
1833+ MultiByteToWideChar (CP_ACP , 0 , shortcut_name , -1 , wsz , sizeof ( wsz )/ sizeof ( wsz [ 0 ]) );
18301834
18311835 /* set the attributes */
18321836 shelllink_ptr -> lpVtbl -> SetPath (shelllink_ptr , shortcut_target );
@@ -2135,7 +2139,7 @@ install_OLE_register(void)
21352139 * result in "to[]".
21362140 */
21372141 static void
2138- dir_remove_last (const char * path , char to [BUFSIZE ])
2142+ dir_remove_last (const char * path , char to [MAX_PATH ])
21392143{
21402144 char c ;
21412145 long last_char_to_copy ;
@@ -2206,7 +2210,7 @@ init_homedir(void)
22062210 if (homepath == NULL || * homepath == NUL )
22072211 homepath = "\\" ;
22082212 if (homedrive != NULL
2209- && strlen (homedrive ) + strlen (homepath ) < MAX_PATH )
2213+ && strlen (homedrive ) + strlen (homepath ) < sizeof ( buf ) )
22102214 {
22112215 sprintf (buf , "%s%s" , homedrive , homepath );
22122216 if (buf [0 ] != NUL )
@@ -2234,10 +2238,9 @@ init_homedir(void)
22342238 buf [p - (var + 1 )] = NUL ;
22352239 exp = getenv (buf );
22362240 if (exp != NULL && * exp != NUL
2237- && strlen (exp ) + strlen (p ) < MAX_PATH )
2241+ && strlen (exp ) + strlen (p ) < sizeof ( buf ) )
22382242 {
2239- _snprintf (buf , MAX_PATH , "%s%s" , exp , p + 1 );
2240- buf [MAX_PATH - 1 ] = NUL ;
2243+ sprintf (buf , "%s%s" , exp , p + 1 );
22412244 var = buf ;
22422245 }
22432246 }
@@ -2351,10 +2354,11 @@ init_directories_choice(void)
23512354
23522355 // Check if the "compiler" directory already exists. That's a good
23532356 // indication that the plugin directories were already created.
2354- if (getenv ("HOME" ) != NULL )
2357+ p = getenv ("HOME" );
2358+ if (p != NULL )
23552359 {
23562360 vimfiles_dir_choice = (int )vimfiles_dir_home ;
2357- sprintf (tmp_dirname , "%s\\vimfiles\\compiler" , getenv ( "HOME" ) );
2361+ sprintf (tmp_dirname , "%s\\vimfiles\\compiler" , p );
23582362 if (stat (tmp_dirname , & st ) == 0 )
23592363 vimfiles_dir_choice = (int )vimfiles_dir_none ;
23602364 }
0 commit comments