PERFORM CORRECT RANGE CHECHING ON "toupper()/tolower()"
authorWiljo Heinen <wiljo@freeside.ki.open.de>
Sun, 2 Aug 1992 00:00:00 +0000 (00:00 +0000)
committerWiljo Heinen <wiljo@freeside.ki.open.de>
Sun, 2 Aug 1992 00:00:00 +0000 (00:00 +0000)
The toupper() and tolower() functions did not do appropriate
range checking, and would shift the value of any ASCII character passed
+/- 32, respectively, without regard to whether the characters so shifted
were letters or not.  This corrects the problem, although, like the rest
of the C library, does not take internationalized character sets into account.

AUTHOR: Wiljo Heinen (wiljo@freeside.ki.open.de)
386BSD-Patchkit: patch00027

usr/src/lib/libc/gen/isctype.c

index d4f6293..e598f10 100644 (file)
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
+ *
+ * PATCHES MAGIC                LEVEL   PATCH THAT GOT US HERE
+ * --------------------         -----   ----------------------
+ * CURRENT PATCH LEVEL:         1       00027
+ * --------------------         -----   ----------------------
+ *
+ * 02 Aug 92   Wiljo Heinen            Fixed toupper()/tolower() range check
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
  */
 
 #if defined(LIBC_SCCS) && !defined(lint)
@@ -119,12 +126,14 @@ isxdigit(c)
 tolower(c)
        int c;
 {
 tolower(c)
        int c;
 {
-       return((c) - 'A' + 'a');
+/* was:        return((c) - 'A' + 'a');*/
+       return ( isupper(c) ? c - 'A' + 'a' : c);
 }
 
 #undef toupper
 toupper(c)
        int c;
 {
 }
 
 #undef toupper
 toupper(c)
        int c;
 {
-       return((c) - 'a' + 'A');
+/* was:        return((c) - 'a' + 'A');*/
+       return ( islower(c) ? c - 'a' + 'A' : c);
 }
 }