Add a move ctor for agg::path_storage.

Without it, MSVC cannot do RVO correctly when the return type is
agg::path_storage. This will be used in
https://pdfium-review.googlesource.com/86514 so that BuildAggPath() can
return agg::path_storage and avoid having an out-parameter. Along the
way, modernize the agg::path_storage ctor, explicitly delete the copy
ctor and various assign operators, and use nullptr when appropriate.

Change-Id: I35a95f9be26728f3aaaa987b3e02aad807014efc
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/86551
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/third_party/agg23/0011-path-storage-move-ctor.patch b/third_party/agg23/0011-path-storage-move-ctor.patch
new file mode 100644
index 0000000..c0fbee5
--- /dev/null
+++ b/third_party/agg23/0011-path-storage-move-ctor.patch
@@ -0,0 +1,67 @@
+diff --git a/third_party/agg23/agg_path_storage.cpp b/third_party/agg23/agg_path_storage.cpp
+index 2cd0caed1..1491e9e33 100644
+--- a/third_party/agg23/agg_path_storage.cpp
++++ b/third_party/agg23/agg_path_storage.cpp
+@@ -43,14 +43,20 @@ path_storage::~path_storage()
+         FX_Free(m_coord_blocks);
+     }
+ }
+-path_storage::path_storage() :
+-    m_total_vertices(0),
+-    m_total_blocks(0),
+-    m_max_blocks(0),
+-    m_coord_blocks(0),
+-    m_cmd_blocks(0),
+-    m_iterator(0)
+-{
++path_storage::path_storage() = default;
++path_storage::path_storage(path_storage&& other) {
++    m_total_vertices = other.m_total_vertices;
++    m_total_blocks = other.m_total_blocks;
++    m_max_blocks = other.m_max_blocks;
++    m_coord_blocks = other.m_coord_blocks;
++    m_cmd_blocks = other.m_cmd_blocks;
++    m_iterator = other.m_iterator;
++    other.m_total_vertices = 0;
++    other.m_total_blocks = 0;
++    other.m_max_blocks = 0;
++    other.m_coord_blocks = nullptr;
++    other.m_cmd_blocks = nullptr;
++    other.m_iterator = 0;
+ }
+ void path_storage::allocate_block(unsigned nb)
+ {
+diff --git a/third_party/agg23/agg_path_storage.h b/third_party/agg23/agg_path_storage.h
+index 55d6df001..8f10ff36d 100644
+--- a/third_party/agg23/agg_path_storage.h
++++ b/third_party/agg23/agg_path_storage.h
+@@ -50,6 +50,10 @@ public:
+     };
+     ~path_storage();
+     path_storage();
++    path_storage(path_storage&& other);
++    path_storage& operator=(path_storage&&) = delete;
++    path_storage(const path_storage&) = delete;
++    path_storage& operator=(const path_storage&) = delete;
+     unsigned last_vertex(float* x, float* y) const;
+     unsigned prev_vertex(float* x, float* y) const;
+     void move_to(float x, float y);
+@@ -116,12 +120,12 @@ private:
+     void allocate_block(unsigned nb);
+     unsigned char* storage_ptrs(float** xy_ptr);
+ private:
+-    unsigned        m_total_vertices;
+-    unsigned        m_total_blocks;
+-    unsigned        m_max_blocks;
+-    float**   m_coord_blocks;
+-    unsigned char** m_cmd_blocks;
+-    unsigned        m_iterator;
++    unsigned        m_total_vertices = 0;
++    unsigned        m_total_blocks = 0;
++    unsigned        m_max_blocks = 0;
++    float**         m_coord_blocks = nullptr;
++    unsigned char** m_cmd_blocks = nullptr;
++    unsigned        m_iterator = 0;
+ };
+ inline unsigned path_storage::vertex(float* x, float* y)
+ {
diff --git a/third_party/agg23/README.pdfium b/third_party/agg23/README.pdfium
index e241f94..dd11888 100644
--- a/third_party/agg23/README.pdfium
+++ b/third_party/agg23/README.pdfium
@@ -14,7 +14,7 @@
 Possibly more?
 0001-gcc-warning.patch: Fix a GCC warning about both enumeral and
 non-enumeral type in conditional.
-0002-ubsan-error-fixes.path: Fix UBSan errors for overflows.
+0002-ubsan-error-fixes.patch: Fix UBSan errors for overflows.
 0003-ubsan-render-line-error.patch: Fix UBSan overflow error in render_line.
 0004-ubsan-sweep-scanline-error.patch: Fix UBSan left shift of negative value
 error in sweep_scanline.
@@ -27,3 +27,4 @@
 0008-namespace.patch: Wrap all AGG code in namespace pdfium.
 0009-infinite-loop.patch: avoid hang in agg_math_stroke.h
 0010-math.patch: includes <math.h>
+0011-path-storage-move-ctor.patch: Add a move ctor for path_storage.
diff --git a/third_party/agg23/agg_path_storage.cpp b/third_party/agg23/agg_path_storage.cpp
index 2cd0cae..1491e9e 100644
--- a/third_party/agg23/agg_path_storage.cpp
+++ b/third_party/agg23/agg_path_storage.cpp
@@ -43,14 +43,20 @@
         FX_Free(m_coord_blocks);
     }
 }
-path_storage::path_storage() :
-    m_total_vertices(0),
-    m_total_blocks(0),
-    m_max_blocks(0),
-    m_coord_blocks(0),
-    m_cmd_blocks(0),
-    m_iterator(0)
-{
+path_storage::path_storage() = default;
+path_storage::path_storage(path_storage&& other) {
+    m_total_vertices = other.m_total_vertices;
+    m_total_blocks = other.m_total_blocks;
+    m_max_blocks = other.m_max_blocks;
+    m_coord_blocks = other.m_coord_blocks;
+    m_cmd_blocks = other.m_cmd_blocks;
+    m_iterator = other.m_iterator;
+    other.m_total_vertices = 0;
+    other.m_total_blocks = 0;
+    other.m_max_blocks = 0;
+    other.m_coord_blocks = nullptr;
+    other.m_cmd_blocks = nullptr;
+    other.m_iterator = 0;
 }
 void path_storage::allocate_block(unsigned nb)
 {
diff --git a/third_party/agg23/agg_path_storage.h b/third_party/agg23/agg_path_storage.h
index 55d6df0..8c2bd36 100644
--- a/third_party/agg23/agg_path_storage.h
+++ b/third_party/agg23/agg_path_storage.h
@@ -50,6 +50,10 @@
     };
     ~path_storage();
     path_storage();
+    path_storage(path_storage&& other);
+    path_storage& operator=(path_storage&&) = delete;
+    path_storage(const path_storage&) = delete;
+    path_storage& operator=(const path_storage&) = delete;
     unsigned last_vertex(float* x, float* y) const;
     unsigned prev_vertex(float* x, float* y) const;
     void move_to(float x, float y);
@@ -116,12 +120,12 @@
     void allocate_block(unsigned nb);
     unsigned char* storage_ptrs(float** xy_ptr);
 private:
-    unsigned        m_total_vertices;
-    unsigned        m_total_blocks;
-    unsigned        m_max_blocks;
-    float**   m_coord_blocks;
-    unsigned char** m_cmd_blocks;
-    unsigned        m_iterator;
+    unsigned        m_total_vertices = 0;
+    unsigned        m_total_blocks = 0;
+    unsigned        m_max_blocks = 0;
+    float**         m_coord_blocks = nullptr;
+    unsigned char** m_cmd_blocks = nullptr;
+    unsigned        m_iterator = 0;
 };
 inline unsigned path_storage::vertex(float* x, float* y)
 {