Reapplied changeset 287 (resample may write pass the output buffer), with a bit optimization

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1968 74dad513-b988-da41-8d7b-12977e46ad98
diff --git a/third_party/resample/src/resamplesubs.c b/third_party/resample/src/resamplesubs.c
index 2cb04eb..51648ae 100644
--- a/third_party/resample/src/resamplesubs.c
+++ b/third_party/resample/src/resamplesubs.c
@@ -259,7 +259,11 @@
     Ystart = Y;
     Yend = Ystart + (unsigned)(nx * pFactor);
     endTime = time + (1<<Np)*(RES_WORD)nx;
-    while (time < endTime)
+
+    // Integer round down in dtb calculation may cause (endTime % dtb > 0), 
+    // so it may cause resample write pass the output buffer (Y >= Yend).
+    // while (time < endTime)
+    while (Y < Yend)
     {
 	xp = &X[time>>Np];      /* Ptr to current input sample */
 	/* Perform left-wing inner product */