Use pb_byte_t = uint8_t when UINT8_MAX is defined (#916)
Adapted from PR#916 by Petteri Aimonen.
diff --git a/docs/migration.md b/docs/migration.md
index 394b4fa..b00fffc 100644
--- a/docs/migration.md
+++ b/docs/migration.md
@@ -6,6 +6,25 @@
error indications are included, in order to make it easier to find this
document.
+Nanopb-0.4.9 (2024-xx-xx)
+-------------------------
+
+### Use uint8_t for pb_byte_t when UINT8_MAX is defined
+
+**Rationale:** Previously `pb_byte_t` was always defined as `uint8_least_t`.
+This could be annoying on some platforms without this define, or when some
+compiles might warn on conversion from `uint8_t`. However not all platforms
+support `uint8_t` sized access.
+
+**Changes:** The `stdint.h` header will define `UINT8_MAX` exactly if `uint8_t`
+is available. Use it to select which type to typedef.
+
+**Required actions:** Usually none. If any compiler warnings are generated,
+they can either be fixed or `PB_BYTE_T_OVERRIDE` can be defined to `uint_least8_t`
+to restore old behavior.
+
+**Error indications:** Implicit conversion from `uint_least8_t` to `uint8_t`.
+
Nanopb-0.4.8 (2023-11-11)
-------------------------
diff --git a/pb.h b/pb.h
index 8745ecc..e90c93a 100644
--- a/pb.h
+++ b/pb.h
@@ -215,12 +215,23 @@
#endif
#endif
+/* Data type for storing encoded data and other byte streams.
+ * This typedef exists to support platforms where uint8_t does not exist.
+ * You can regard it as equivalent on uint8_t on other platforms.
+ */
+#if defined(PB_BYTE_T_OVERRIDE)
+typedef PB_BYTE_T_OVERRIDE pb_byte_t;
+#elif defined(UINT8_MAX)
+typedef uint8_t pb_byte_t;
+#else
+typedef uint_least8_t pb_byte_t;
+#endif
+
/* List of possible field types. These are used in the autogenerated code.
* Least-significant 4 bits tell the scalar type
* Most-significant 4 bits specify repeated/required/packed etc.
*/
-
-typedef uint_least8_t pb_type_t;
+typedef pb_byte_t pb_type_t;
/**** Field data types ****/
@@ -301,12 +312,6 @@
#endif
#define PB_SIZE_MAX ((pb_size_t)-1)
-/* Data type for storing encoded data and other byte streams.
- * This typedef exists to support platforms where uint8_t does not exist.
- * You can regard it as equivalent on uint8_t on other platforms.
- */
-typedef uint_least8_t pb_byte_t;
-
/* Forward declaration of struct types */
typedef struct pb_istream_s pb_istream_t;
typedef struct pb_ostream_s pb_ostream_t;
diff --git a/tests/regression/issue_485/uint8.expected b/tests/regression/issue_485/uint8.expected
index 291ab81..c110c2d 100644
--- a/tests/regression/issue_485/uint8.expected
+++ b/tests/regression/issue_485/uint8.expected
@@ -1,3 +1,3 @@
-! ^\s*[^/* ].*uint8_t
-! ^\s*[^/* ].*int8_t
+! ^(?!.*\*)(?!.*typedef).*uint8_t.*
+! ^(?!.*\*)(?!.*typedef).*int8_t.*