diff --git a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
index 7d65028601c8..87c1480fba72 100644
--- a/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
@@ -1342,7 +1342,7 @@ public:
       return false;
 
     // Get the second character and switch on its value
-    switch (FormatStr[2]) {
+    switch (FormatStr[1]) {
     case 'c': {
       // sprintf(dest,"%c",chr) -> store chr, dest
       Value *V = CastInst::createTruncOrBitCast(CI->getOperand(3),