On Fri, Aug 22, 2008 at 10:25 PM, Bram Moolenaar <[EMAIL PROTECTED]> wrote:
>
> Jan Minar wrote:
>
>> > Thanks. I'll have a good look at it later. One thing I noticed: you
>> > don't need to give an error message for running out of memory at this
>> > level, it's already done at a lower level in alloc(). There it also
>>
>> That's what I thought, too. But vim_strsave_shellescape() is
>> documented to return NULL when out of memory:
>>
>> src/misc2.c:
>>
>> 1279 * Returns the result in allocated memory, NULL if we have run out.
>> 1280 */
>> 1281 char_u *
>> 1282 vim_strsave_shellescape(string, do_special)
>
> Yeah, but the out-of-memory message will already been given. So you can
> just abort the operation.
Thanks for the feedback.
My understanding of how vim malloc() wrappers worked was incorrect.
I've updated the patch. These are the changes from the previous
version:
--- - 2008-08-23 07:10:35.931412125 +0100
+++ src/normal.c 2008-08-23 07:07:44.000000000 +0100
@@ -5518,12 +5518,10 @@
if (cmdchar == 'K' && !kp_help)
{
/* Sanitize properly */
- if ((p = vim_strsave_shellescape(ptr, TRUE)) == NULL);
- {
- printf("ERROR: out of memory\n");
- exit(1);
- }
- (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1);
+ if ((p = vim_strsave_shellescape(ptr, TRUE)) == NULL ||
+ (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1) == NULL)
+ /* Out of memory */
+ return;
STRCAT(buf, p);
vim_free(p);
}
Earlier in this function, the code does just return when out of
memory, so that's what I'll do as well. The realloc() return value
was not checked, so I fixed that as well. The updated patch (version
2) is attached.
Cheers,
Jan.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---