From fc44bcb9343984091d9cd1a9474d03d78a988332 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 11 Feb 2012 21:11:11 +0100 Subject: [PATCH] Base64: Made thread-safe --- ucw/base64.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ucw/base64.c b/ucw/base64.c index 9865f4c6..56f30766 100644 --- a/ucw/base64.c +++ b/ucw/base64.c @@ -11,6 +11,7 @@ #include "ucw/lib.h" #include "ucw/base64.h" +#include "ucw/threads.h" #include @@ -67,16 +68,17 @@ base64_decode(byte *dest, const byte *src, uns len) static uns table_built = 0; if (table_built == 0) { - byte *chp; - table_built = 1; + ucwlib_lock(); for(ch = 0; ch < 256; ch++) { - chp = strchr(base64_table, ch); + byte *chp = strchr(base64_table, ch); if(chp) { reverse_table[ch] = chp - base64_table; } else { reverse_table[ch] = 0xff; } } + table_built = 1; + ucwlib_unlock(); } /* run through the whole string, converting as we go */ -- 2.39.5