Mercurial > vim
comparison src/channel.c @ 9355:40c8a8b012b5 v7.4.1959
commit https://github.com/vim/vim/commit/aad30bbcde2b268e2fffb6fd1443f27ebda9d1ff
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 26 17:31:03 2016 +0200
patch 7.4.1959
Problem: Crash when running test_channel.vim on Windows.
Solution: Check for NULL pointer result from FormatMessage(). (Christian
Brabandt)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 26 Jun 2016 17:45:04 +0200 |
parents | 9f97a6290c63 |
children | 2465b6cda394 |
comparison
equal
deleted
inserted
replaced
9354:5ddc3234b057 | 9355:40c8a8b012b5 |
---|---|
259 { | 259 { |
260 static LPVOID msgbuf = NULL; | 260 static LPVOID msgbuf = NULL; |
261 char_u *ptr; | 261 char_u *ptr; |
262 | 262 |
263 if (msgbuf) | 263 if (msgbuf) |
264 { | |
264 LocalFree(msgbuf); | 265 LocalFree(msgbuf); |
266 msgbuf = NULL; | |
267 } | |
265 FormatMessage( | 268 FormatMessage( |
266 FORMAT_MESSAGE_ALLOCATE_BUFFER | | 269 FORMAT_MESSAGE_ALLOCATE_BUFFER | |
267 FORMAT_MESSAGE_FROM_SYSTEM | | 270 FORMAT_MESSAGE_FROM_SYSTEM | |
268 FORMAT_MESSAGE_IGNORE_INSERTS, | 271 FORMAT_MESSAGE_IGNORE_INSERTS, |
269 NULL, | 272 NULL, |
270 eno, | 273 eno, |
271 MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), | 274 MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), |
272 (LPTSTR) &msgbuf, | 275 (LPTSTR) &msgbuf, |
273 0, | 276 0, |
274 NULL); | 277 NULL); |
275 /* chomp \r or \n */ | 278 if (msgbuf != NULL) |
276 for (ptr = (char_u *)msgbuf; *ptr; ptr++) | 279 /* chomp \r or \n */ |
277 switch (*ptr) | 280 for (ptr = (char_u *)msgbuf; *ptr; ptr++) |
278 { | 281 switch (*ptr) |
279 case '\r': | 282 { |
280 STRMOVE(ptr, ptr + 1); | 283 case '\r': |
281 ptr--; | 284 STRMOVE(ptr, ptr + 1); |
282 break; | 285 ptr--; |
283 case '\n': | 286 break; |
284 if (*(ptr + 1) == '\0') | 287 case '\n': |
285 *ptr = '\0'; | 288 if (*(ptr + 1) == '\0') |
286 else | 289 *ptr = '\0'; |
287 *ptr = ' '; | 290 else |
288 break; | 291 *ptr = ' '; |
289 } | 292 break; |
293 } | |
290 return msgbuf; | 294 return msgbuf; |
291 } | 295 } |
292 #endif | 296 #endif |
293 | 297 |
294 /* | 298 /* |
1434 ch_logn(channel, "Still %d more lines to write", | 1438 ch_logn(channel, "Still %d more lines to write", |
1435 buf->b_ml.ml_line_count - lnum + 1); | 1439 buf->b_ml.ml_line_count - lnum + 1); |
1436 } | 1440 } |
1437 | 1441 |
1438 /* | 1442 /* |
1439 * Handle buffer "buf" beeing freed, remove it from any channels. | 1443 * Handle buffer "buf" being freed, remove it from any channels. |
1440 */ | 1444 */ |
1441 void | 1445 void |
1442 channel_buffer_free(buf_T *buf) | 1446 channel_buffer_free(buf_T *buf) |
1443 { | 1447 { |
1444 channel_T *channel; | 1448 channel_T *channel; |
2192 free_tv(tv); | 2196 free_tv(tv); |
2193 } | 2197 } |
2194 } | 2198 } |
2195 else if (p_verbose > 2) | 2199 else if (p_verbose > 2) |
2196 { | 2200 { |
2197 ch_errors(channel, "Receved unknown command: %s", (char *)cmd); | 2201 ch_errors(channel, "Received unknown command: %s", (char *)cmd); |
2198 EMSG2("E905: received unknown command: %s", cmd); | 2202 EMSG2("E905: received unknown command: %s", cmd); |
2199 } | 2203 } |
2200 } | 2204 } |
2201 | 2205 |
2202 /* | 2206 /* |
3184 chanpart->ch_block_id = id; | 3188 chanpart->ch_block_id = id; |
3185 for (;;) | 3189 for (;;) |
3186 { | 3190 { |
3187 more = channel_parse_json(channel, part); | 3191 more = channel_parse_json(channel, part); |
3188 | 3192 |
3189 /* search for messsage "id" */ | 3193 /* search for message "id" */ |
3190 if (channel_get_json(channel, part, id, rettv) == OK) | 3194 if (channel_get_json(channel, part, id, rettv) == OK) |
3191 { | 3195 { |
3192 chanpart->ch_block_id = 0; | 3196 chanpart->ch_block_id = 0; |
3193 return OK; | 3197 return OK; |
3194 } | 3198 } |
3424 } | 3428 } |
3425 | 3429 |
3426 /* | 3430 /* |
3427 * Common for "ch_sendexpr()" and "ch_sendraw()". | 3431 * Common for "ch_sendexpr()" and "ch_sendraw()". |
3428 * Returns the channel if the caller should read the response. | 3432 * Returns the channel if the caller should read the response. |
3429 * Sets "part_read" to the the read fd. | 3433 * Sets "part_read" to the read fd. |
3430 * Otherwise returns NULL. | 3434 * Otherwise returns NULL. |
3431 */ | 3435 */ |
3432 channel_T * | 3436 channel_T * |
3433 send_common( | 3437 send_common( |
3434 typval_T *argvars, | 3438 typval_T *argvars, |
4297 ch_log(job->jv_channel, "Freeing job"); | 4301 ch_log(job->jv_channel, "Freeing job"); |
4298 if (job->jv_channel != NULL) | 4302 if (job->jv_channel != NULL) |
4299 { | 4303 { |
4300 /* The link from the channel to the job doesn't count as a reference, | 4304 /* The link from the channel to the job doesn't count as a reference, |
4301 * thus don't decrement the refcount of the job. The reference from | 4305 * thus don't decrement the refcount of the job. The reference from |
4302 * the job to the channel does count the refrence, decrement it and | 4306 * the job to the channel does count the reference, decrement it and |
4303 * NULL the reference. We don't set ch_job_killed, unreferencing the | 4307 * NULL the reference. We don't set ch_job_killed, unreferencing the |
4304 * job doesn't mean it stops running. */ | 4308 * job doesn't mean it stops running. */ |
4305 job->jv_channel->ch_job = NULL; | 4309 job->jv_channel->ch_job = NULL; |
4306 channel_unref(job->jv_channel); | 4310 channel_unref(job->jv_channel); |
4307 } | 4311 } |