Skip to content

Commit 3e4978b

Browse files
committed
Fix free-slot search in PgSetResultId so it actually works.
1 parent e313eb8 commit 3e4978b

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/interfaces/libpgtcl/pgtclId.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
1515
* IDENTIFICATION
16-
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.36 2002/09/23 01:43:23 momjian Exp $
16+
* $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/pgtclId.c,v 1.37 2002/10/17 14:53:32 tgl Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -340,30 +340,34 @@ PgSetResultId(Tcl_Interp *interp, char *connid_c, PGresult *res)
340340
return TCL_ERROR;
341341
connid = (Pg_ConnectionId *) Tcl_GetChannelInstanceData(conn_chan);
342342

343-
for (resid = connid->res_last + 1; resid != connid->res_last; resid++)
343+
/* search, starting at slot after the last one used */
344+
resid = connid->res_last;
345+
for (;;)
344346
{
345-
if (resid == connid->res_max)
346-
{
347+
/* advance, with wraparound */
348+
if (++resid >= connid->res_max)
347349
resid = 0;
348-
break;
349-
}
350+
/* this slot empty? */
350351
if (!connid->results[resid])
351352
{
352353
connid->res_last = resid;
353-
break;
354+
break; /* success exit */
354355
}
356+
/* checked all slots? */
357+
if (resid == connid->res_last)
358+
break; /* failure exit */
355359
}
356360

357361
if (connid->results[resid])
358362
{
359-
if (connid->res_max == connid->res_hardmax)
363+
/* no free slot found, so try to enlarge array */
364+
if (connid->res_max >= connid->res_hardmax)
360365
{
361366
Tcl_SetResult(interp, "hard limit on result handles reached",
362367
TCL_STATIC);
363368
return TCL_ERROR;
364369
}
365-
connid->res_last = connid->res_max;
366-
resid = connid->res_max;
370+
connid->res_last = resid = connid->res_max;
367371
connid->res_max *= 2;
368372
if (connid->res_max > connid->res_hardmax)
369373
connid->res_max = connid->res_hardmax;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy