Merge to XFA: Kill remaining sprintfs
[pdfium.git] / fpdfsdk / src / fsdk_baseannot.cpp
index 90e22d3..e80d3b8 100644 (file)
@@ -358,13 +358,16 @@ CFX_ByteString CPDFSDK_DateTime::ToPDFDateTimeString()
 {
        CFX_ByteString dtStr;
        char tempStr[32];
-       sprintf(tempStr, "D:%04d%02d%02d%02d%02d%02d", dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
+       memset(tempStr, 0, sizeof(tempStr));
+       FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "D:%04d%02d%02d%02d%02d%02d",
+                   dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second);
        dtStr = CFX_ByteString(tempStr);
        if (dt.tzHour < 0)
                dtStr += CFX_ByteString("-");
        else
                dtStr += CFX_ByteString("+");
-       sprintf(tempStr, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute);
+       memset(tempStr, 0, sizeof(tempStr));
+       FXSYS_snprintf(tempStr, sizeof(tempStr) - 1, "%02d'%02d'", abs(dt.tzHour), dt.tzMinute);
        dtStr += CFX_ByteString(tempStr);
        return dtStr;
 }
@@ -1058,7 +1061,7 @@ void CPDFSDK_BAAnnot::WriteAppearance(const CFX_ByteString& sAPType, const CPDF_
                pStreamDict->SetAtRect("BBox", rcBBox);         
        }
        
-       pStream->SetData((FX_BYTE*)(FX_LPCSTR)sContents, sContents.GetLength(), FALSE, FALSE);
+       pStream->SetData((FX_BYTE*)sContents.c_str(), sContents.GetLength(), FALSE, FALSE);
 }
 
 #define BA_ANNOT_MINWIDTH                      1
@@ -1086,43 +1089,30 @@ FX_BOOL CPDFSDK_BAAnnot::IsVisible() const
 
 CPDF_Action CPDFSDK_BAAnnot::GetAction() const
 {
-       ASSERT(m_pAnnot != NULL);
-       ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-       
-       return m_pAnnot->m_pAnnotDict->GetDict("A");
+       return CPDF_Action(m_pAnnot->m_pAnnotDict->GetDict("A"));
 }
 
 void CPDFSDK_BAAnnot::SetAction(const CPDF_Action& action)
 {
-       ASSERT(m_pAnnot != NULL);
-       ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-       
-       ASSERT(action != NULL);
-       
-       if ((CPDF_Action&)action != m_pAnnot->m_pAnnotDict->GetDict("A"))
+       ASSERT(action);
+       if ((CPDF_Action&)action != CPDF_Action(m_pAnnot->m_pAnnotDict->GetDict("A")))
        {
                CPDF_Document* pDoc = m_pPageView->GetPDFDocument();
-               ASSERT(pDoc != NULL);
-               
-               if (action.m_pDict && (action.m_pDict->GetObjNum() == 0))
-                       pDoc->AddIndirectObject(action.m_pDict); 
-               m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, action.m_pDict->GetObjNum());
+               CPDF_Dictionary* pDict = action.GetDict();
+               if (pDict && pDict->GetObjNum() == 0) {
+                       pDoc->AddIndirectObject(pDict);
+               }
+               m_pAnnot->m_pAnnotDict->SetAtReference("A", pDoc, pDict->GetObjNum());
        }
 }
 
 void CPDFSDK_BAAnnot::RemoveAction()
 {
-       ASSERT(m_pAnnot != NULL);
-       ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-       
        m_pAnnot->m_pAnnotDict->RemoveAt("A");
 }
 
 CPDF_AAction CPDFSDK_BAAnnot::GetAAction() const
 {
-       ASSERT(m_pAnnot != NULL);
-       ASSERT(m_pAnnot->m_pAnnotDict != NULL);
-       
        return m_pAnnot->m_pAnnotDict->GetDict("AA");
 }
 
@@ -1147,17 +1137,14 @@ void CPDFSDK_BAAnnot::RemoveAAction()
 CPDF_Action    CPDFSDK_BAAnnot::GetAAction(CPDF_AAction::AActionType eAAT)
 {
        CPDF_AAction AAction = GetAAction();
-       
+
        if (AAction.ActionExist(eAAT))
-       {
                return AAction.GetAction(eAAT);
-       }
-       else if (eAAT == CPDF_AAction::ButtonUp)
-       {
+
+       if (eAAT == CPDF_AAction::ButtonUp)
                return GetAction();
-       }
-       
-       return NULL;
+
+       return CPDF_Action();
 }
 
 FX_BOOL CPDFSDK_BAAnnot::IsXFAField()