[Libreoffice-commits] core.git: include/vcl vcl/unx

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Tue Jan 28 17:36:54 UTC 2020


 include/vcl/ppdparser.hxx                      |    7 +++++--
 vcl/unx/generic/print/printerjob.cxx           |    5 +++--
 vcl/unx/generic/printer/cpdmgr.cxx             |    7 +++++--
 vcl/unx/generic/printer/cupsmgr.cxx            |    5 +++--
 vcl/unx/generic/printer/ppdparser.cxx          |    6 ++----
 vcl/unx/generic/printer/printerinfomanager.cxx |   17 +++++++++++------
 6 files changed, 29 insertions(+), 18 deletions(-)

New commits:
commit 545f198a3baa5544919454054d591d1a331498f7
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Tue Jan 28 15:00:07 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Jan 28 18:36:14 2020 +0100

    Use better types for PPDContext::countValuesModified/getModifiedKey
    
    Change-Id: I663216e94fed3ce8f61cef0aeab3cd79f358b7fb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87632
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/include/vcl/ppdparser.hxx b/include/vcl/ppdparser.hxx
index 2d0701c4a859..a0a59c4a8d80 100644
--- a/include/vcl/ppdparser.hxx
+++ b/include/vcl/ppdparser.hxx
@@ -19,6 +19,9 @@
 #ifndef INCLUDED_VCL_PPDPARSER_HXX
 #define INCLUDED_VCL_PPDPARSER_HXX
 
+#include <sal/config.h>
+
+#include <cstddef>
 #include <memory>
 #include <unordered_map>
 #include <vector>
@@ -246,8 +249,8 @@ public:
     const PPDValue* getValue( const PPDKey* ) const;
     const PPDValue* setValue( const PPDKey*, const PPDValue*, bool bDontCareForConstraints = false );
 
-    int countValuesModified() const { return m_aCurrentValues.size(); }
-    const PPDKey* getModifiedKey( int n ) const;
+    std::size_t countValuesModified() const { return m_aCurrentValues.size(); }
+    const PPDKey* getModifiedKey( std::size_t n ) const;
 
     // public wrapper for the private method
     bool checkConstraints( const PPDKey*, const PPDValue* );
diff --git a/vcl/unx/generic/print/printerjob.cxx b/vcl/unx/generic/print/printerjob.cxx
index 5a5bc6d9e6b3..8269b8d4be01 100644
--- a/vcl/unx/generic/print/printerjob.cxx
+++ b/vcl/unx/generic/print/printerjob.cxx
@@ -38,6 +38,7 @@
 #include <osl/security.hxx>
 
 #include <algorithm>
+#include <cstddef>
 #include <deque>
 #include <vector>
 
@@ -682,8 +683,8 @@ bool PrinterJob::writeFeatureList( osl::File* pFile, const JobData& rJob, bool b
         ( m_aLastJobData.m_pParser == rJob.m_pParser || m_aLastJobData.m_pParser == nullptr )
         )
     {
-        int i;
-        int nKeys = rJob.m_aContext.countValuesModified();
+        std::size_t i;
+        std::size_t nKeys = rJob.m_aContext.countValuesModified();
         ::std::vector< const PPDKey* > aKeys( nKeys );
         for(  i = 0; i < nKeys; i++ )
             aKeys[i] = rJob.m_aContext.getModifiedKey( i );
diff --git a/vcl/unx/generic/printer/cpdmgr.cxx b/vcl/unx/generic/printer/cpdmgr.cxx
index cae2a4e1ab03..bebd568330c5 100644
--- a/vcl/unx/generic/printer/cpdmgr.cxx
+++ b/vcl/unx/generic/printer/cpdmgr.cxx
@@ -17,6 +17,9 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <cstddef>
 #include <unistd.h>
 
 #include <unx/cpdmgr.hxx>
@@ -604,8 +607,8 @@ void CPDManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner,
     builder = g_variant_builder_new(G_VARIANT_TYPE("a(ss)"));
     g_variant_builder_add(builder, "(ss)", "job-name", rJobName.getStr());
     if( rJob.m_pParser ==  rJob.m_aContext.getParser() &&  rJob.m_pParser ) {
-        int i;
-        int nKeys = rJob.m_aContext.countValuesModified();
+        std::size_t i;
+        std::size_t nKeys = rJob.m_aContext.countValuesModified();
         ::std::vector< const PPDKey* > aKeys( nKeys );
         for(  i = 0; i < nKeys; i++ )
             aKeys[i] = rJob.m_aContext.getModifiedKey( i );
diff --git a/vcl/unx/generic/printer/cupsmgr.cxx b/vcl/unx/generic/printer/cupsmgr.cxx
index 17e8112f4bff..f2251cb886f3 100644
--- a/vcl/unx/generic/printer/cupsmgr.cxx
+++ b/vcl/unx/generic/printer/cupsmgr.cxx
@@ -40,6 +40,7 @@
 #include <vcl/window.hxx>
 
 #include <algorithm>
+#include <cstddef>
 
 using namespace psp;
 using namespace osl;
@@ -618,8 +619,8 @@ void CUPSManager::getOptionsFromDocumentSetup( const JobData& rJob, bool bBanner
     // sanity check
     if( rJob.m_pParser == rJob.m_aContext.getParser() && rJob.m_pParser )
     {
-        int i;
-        int nKeys = rJob.m_aContext.countValuesModified();
+        std::size_t i;
+        std::size_t nKeys = rJob.m_aContext.countValuesModified();
         ::std::vector< const PPDKey* > aKeys( nKeys );
         for(  i = 0; i < nKeys; i++ )
             aKeys[i] = rJob.m_aContext.getModifiedKey( i );
diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx
index ec9960eab94b..ffa6c873c13f 100644
--- a/vcl/unx/generic/printer/ppdparser.cxx
+++ b/vcl/unx/generic/printer/ppdparser.cxx
@@ -19,7 +19,6 @@
 
 #include <sal/config.h>
 
-#include <cassert>
 #include <stdlib.h>
 
 #include <comphelper/string.hxx>
@@ -1648,10 +1647,9 @@ PPDContext& PPDContext::operator=( PPDContext&& rCopy )
     return *this;
 }
 
-const PPDKey* PPDContext::getModifiedKey( int n ) const
+const PPDKey* PPDContext::getModifiedKey( std::size_t n ) const
 {
-    assert(n >= 0);
-    if( m_aCurrentValues.size() <= o3tl::make_unsigned(n) )
+    if( m_aCurrentValues.size() <= n )
         return nullptr;
 
     hash_type::const_iterator it = m_aCurrentValues.begin();
diff --git a/vcl/unx/generic/printer/printerinfomanager.cxx b/vcl/unx/generic/printer/printerinfomanager.cxx
index 7bdddb5cfed2..8e96c41e0f9a 100644
--- a/vcl/unx/generic/printer/printerinfomanager.cxx
+++ b/vcl/unx/generic/printer/printerinfomanager.cxx
@@ -39,6 +39,7 @@
 // the group of the global defaults
 #define GLOBAL_DEFAULTS_GROUP "__Global_Printer_Defaults__"
 
+#include <cstddef>
 #include <unordered_set>
 
 using namespace psp;
@@ -346,7 +347,7 @@ void PrinterInfoManager::initialize()
                     // without constraints which might end up badly
                     // this feature should be use with caution
                     // it is mainly to select default paper sizes for new printers
-                    for( int nPPDValueModified = 0; nPPDValueModified < m_aGlobalDefaults.m_aContext.countValuesModified(); nPPDValueModified++ )
+                    for( std::size_t nPPDValueModified = 0; nPPDValueModified < m_aGlobalDefaults.m_aContext.countValuesModified(); nPPDValueModified++ )
                     {
                         const PPDKey* pDefKey = m_aGlobalDefaults.m_aContext.getModifiedKey( nPPDValueModified );
                         const PPDValue* pDefValue = m_aGlobalDefaults.m_aContext.getValue( pDefKey );
@@ -599,12 +600,16 @@ void PrinterInfoManager::setDefaultPaper( PPDContext& rContext ) const
     if( ! pPageSizeKey )
         return;
 
-    int nModified = rContext.countValuesModified();
-    while( nModified-- &&
-        rContext.getModifiedKey( nModified ) != pPageSizeKey )
-        ;
+    std::size_t nModified = rContext.countValuesModified();
+    auto set = false;
+    for (std::size_t i = 0; i != nModified; ++i) {
+        if (rContext.getModifiedKey(i) == pPageSizeKey) {
+            set = true;
+            break;
+        }
+    }
 
-    if( nModified >= 0 ) // paper was set already, do not modify
+    if( set ) // paper was set already, do not modify
     {
         #if OSL_DEBUG_LEVEL > 1
         fprintf( stderr, "not setting default paper, already set %s\n",


More information about the Libreoffice-commits mailing list