fallintoplace commented on code in PR #846:
URL: https://github.com/apache/iceberg-cpp/pull/846#discussion_r3651166829


##########
src/iceberg/table_metadata.cc:
##########
@@ -517,11 +517,18 @@ int32_t 
TableMetadataUtil::ParseVersionFromLocation(std::string_view metadata_lo
   size_t version_start = metadata_location.find_last_of('/') + 1;
   size_t version_end = metadata_location.find('-', version_start);
 
+  if (version_end == std::string::npos) {
+    return -1;
+  }
+
   int32_t version = -1;
-  if (version_end != std::string::npos) {
-    std::from_chars(metadata_location.data() + version_start,
-                    metadata_location.data() + version_end, version);
+  const auto* version_begin = metadata_location.data() + version_start;
+  const auto* version_limit = metadata_location.data() + version_end;
+  const auto [ptr, ec] = std::from_chars(version_begin, version_limit, 
version);
+  if (ec != std::errc{} || ptr != version_limit) {
+    return -1;

Review Comment:
   I considered that, but a parse failure is intentionally handled by starting 
at version 0, which matches the Java behavior. Returning the error from `Write` 
would change that fallback. Since this is a private helper with one caller and 
the `-1` behavior is documented, I think keeping the sentinel is simpler here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to