Ticket #7104: 0002-TBQueue-Guard-against-negative-maximum-queue-size-by.patch

File 0002-TBQueue-Guard-against-negative-maximum-queue-size-by.patch, 1.1 KB (added by joeyadams, 21 months ago)

TBQueue: Guard against negative maximum queue size (by replacing it with 0)

  • Control/Concurrent/STM/TBQueue.hs

    From e638ce6397710da5f5f180dcf516eb1b1a6dc9a9 Mon Sep 17 00:00:00 2001
    From: Joey Adams <joeyadams3.14159@gmail.com>
    Date: Sun, 29 Jul 2012 21:23:18 -0400
    Subject: [PATCH 2/3] TBQueue: Guard against negative maximum queue size (by replacing it with 0)
    
    ---
     Control/Concurrent/STM/TBQueue.hs |    4 ++--
     1 files changed, 2 insertions(+), 2 deletions(-)
    
    diff --git a/Control/Concurrent/STM/TBQueue.hs b/Control/Concurrent/STM/TBQueue.hs
    index 6f531c0..a3ff2da 100644
    a b newTBQueue size = do 
    7777  read  <- newTVar [] 
    7878  write <- newTVar [] 
    7979  rsize <- newTVar 0 
    80   wsize <- newTVar $! size 
     80  wsize <- newTVar $! if size < 0 then 0 else size 
    8181  return (TBQueue rsize read wsize write) 
    8282 
    8383-- |@IO@ version of 'newTBQueue'.  This is useful for creating top-level 
    newTBQueueIO size = do 
    8989  read  <- newTVarIO [] 
    9090  write <- newTVarIO [] 
    9191  rsize <- newTVarIO 0 
    92   wsize <- newTVarIO $! size 
     92  wsize <- newTVarIO $! if size < 0 then 0 else size 
    9393  return (TBQueue rsize read wsize write) 
    9494 
    9595-- |Write a value to a 'TBQueue'; blocks if the queue is full.