Make small improvements to FPDFFont_GetGlyphPath().

- Make sure the `glyph` argument can be safely casted to wchar_t.
- Use spans instead of vectors.
- Make the character position span empty. The existing dummy value never
  gets used.
- Move a nullptr check to where it is actually needed.

Change-Id: I52a4b6f2ad538034dc9a6f02b52a7d83135df812
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/91833
Reviewed-by: Daniel Hosseinian <dhoss@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/fpdfsdk/fpdf_edittext.cpp b/fpdfsdk/fpdf_edittext.cpp
index ca7c52b..37fac90 100644
--- a/fpdfsdk/fpdf_edittext.cpp
+++ b/fpdfsdk/fpdf_edittext.cpp
@@ -34,6 +34,7 @@
 #include "third_party/base/check.h"
 #include "third_party/base/check_op.h"
 #include "third_party/base/containers/contains.h"
+#include "third_party/base/numerics/safe_conversions.h"
 
 // These checks are here because core/ and public/ cannot depend on each other.
 static_assert(static_cast<int>(TextRenderingMode::MODE_UNKNOWN) ==
@@ -724,19 +725,23 @@
   if (!pFont)
     return nullptr;
 
-  std::vector<TextCharPos> pos = GetCharPosList(
-      std::vector<uint32_t>{
-          pFont->CharCodeFromUnicode(static_cast<wchar_t>(glyph))},
-      std::vector<float>{0.0f}, pFont, font_size);
+  if (!pdfium::base::IsValueInRangeForNumericType<wchar_t>(glyph))
+    return nullptr;
+
+  uint32_t charcode = pFont->CharCodeFromUnicode(static_cast<wchar_t>(glyph));
+  std::vector<TextCharPos> pos =
+      GetCharPosList(pdfium::make_span(&charcode, 1),
+                     pdfium::span<const float>(), pFont, font_size);
 
   CFX_Font* pCfxFont;
   if (pos[0].m_FallbackFontPosition == -1) {
     pCfxFont = pFont->GetFont();
+    DCHECK(pCfxFont);  // Never null.
   } else {
     pCfxFont = pFont->GetFontFallback(pos[0].m_FallbackFontPosition);
+    if (!pCfxFont)
+      return nullptr;
   }
-  if (!pCfxFont)
-    return nullptr;
 
   const CFX_Path* pPath =
       pCfxFont->LoadGlyphPath(pos[0].m_GlyphIndex, pos[0].m_FontCharWidth);