Browse Source

Fix inifinite loop while parsing subdirs.

Improved clarity of the original while loop.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Slávek Banko 4 months ago
parent
commit
82824eab47
Signed by: Slávek Banko <slavek.banko@axis.cz> GPG Key ID: 608F5293A04BE668
2 changed files with 13 additions and 7 deletions
  1. 5
    3
      krename/batchrenamer.cpp
  2. 8
    4
      krename/krenameimpl.cpp

+ 5
- 3
krename/batchrenamer.cpp View File

@@ -839,8 +839,11 @@ void BatchRenamer::parseSubdirs( data* f )
839 839
 
840 840
         // create the missing subdir now
841 841
         int i = 0;
842
-        TQString d = "";
843
-        while (!(d = dirs.section("/", i, i, TQString::SectionSkipEmpty)).isEmpty()) { // asignment here!
842
+        TQString d = TQString::null;
843
+        for (d = dirs.section("/", i, i, TQString::SectionSkipEmpty);
844
+             !d.isEmpty();
845
+             i++, d = dirs.section("/", i, i, TQString::SectionSkipEmpty))
846
+        {
844 847
             KURL url = f->dst.url;
845 848
             // it is important to unescape here
846 849
             // to support dirnames containing "&" or 
@@ -852,7 +855,6 @@ void BatchRenamer::parseSubdirs( data* f )
852 855
 
853 856
             f->dst.url.addPath( d );
854 857
             f->dst.directory.append( d + "/" );
855
-            i++;
856 858
         }
857 859
     }
858 860
 }

+ 8
- 4
krename/krenameimpl.cpp View File

@@ -1171,14 +1171,18 @@ bool KRenameImpl::setupBatchRenamer( BatchRenamer* b, bool preview )
1171 1171
 
1172 1172
             int i = 0;
1173 1173
             TQString d = "/";
1174
-            while (!(d += url.section( "/", i, i, TQString::SectionSkipEmpty)).isEmpty()) { // asignment here!
1175
-                if (!TDEIO::NetAccess::exists(d, false, parent) && !TDEIO::NetAccess::mkdir(d, parent, -1))
1174
+            TQString ds = TQString::null;
1175
+            for (ds = url.section("/", i, i, TQString::SectionSkipEmpty);
1176
+                 !ds.isEmpty();
1177
+                 i++, d.append("/"), ds = url.section("/", i, i, TQString::SectionSkipEmpty))
1178
+            {
1179
+                d += ds;
1180
+                if (!TDEIO::NetAccess::exists(d, false, parent) &&
1181
+                    !TDEIO::NetAccess::mkdir(d, parent, -1))
1176 1182
                 {
1177 1183
                     tqDebug( "Can't create %s", d.latin1() );
1178 1184
                     break;
1179 1185
                 }
1180
-                d.append( "/" );
1181
-                i++;
1182 1186
             }
1183 1187
         }
1184 1188
 

Loading…
Cancel
Save