0004-xenpmd-make-32-bit-gcc-8-1-non-debug-build-work.patch 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. From e75c9dc85fdeeeda0b98d8cd8d784e0508c3ffb8 Mon Sep 17 00:00:00 2001
  2. From: Wei Liu <wei.liu2@citrix.com>
  3. Date: Thu, 26 Jul 2018 15:58:54 +0100
  4. Subject: [PATCH] xenpmd: make 32 bit gcc 8.1 non-debug build work
  5. 32 bit gcc 8.1 non-debug build yields:
  6. xenpmd.c:354:23: error: '%02x' directive output may be truncated writing between 2 and 8 bytes into a region of size 3 [-Werror=format-truncation=]
  7. snprintf(val, 3, "%02x",
  8. ^~~~
  9. xenpmd.c:354:22: note: directive argument in the range [40, 2147483778]
  10. snprintf(val, 3, "%02x",
  11. ^~~~~~
  12. xenpmd.c:354:5: note: 'snprintf' output between 3 and 9 bytes into a destination of size 3
  13. snprintf(val, 3, "%02x",
  14. ^~~~~~~~~~~~~~~~~~~~~~~~
  15. (unsigned int)(9*4 +
  16. ~~~~~~~~~~~~~~~~~~~~
  17. strlen(info->model_number) +
  18. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. strlen(info->serial_number) +
  20. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  21. strlen(info->battery_type) +
  22. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  23. strlen(info->oem_info) + 4));
  24. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  25. All info->* used in calculation are 32 bytes long, and the parsing
  26. code makes sure they are null-terminated, so the end result of the
  27. expression won't exceed 255, which should be able to be fit into 3
  28. bytes in hexadecimal format.
  29. Add an assertion to make gcc happy.
  30. Signed-off-by: Wei Liu <wei.liu2@citrix.com>
  31. Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
  32. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  33. [Retrieved from:
  34. https://github.com/xen-project/xen/commit/e75c9dc85fdeeeda0b98d8cd8d784e0508c3ffb8]
  35. ---
  36. tools/xenpmd/xenpmd.c | 12 ++++++------
  37. 1 file changed, 6 insertions(+), 6 deletions(-)
  38. diff --git a/tools/xenpmd/xenpmd.c b/tools/xenpmd/xenpmd.c
  39. index 56412a9a81c..1c801caa712 100644
  40. --- a/tools/xenpmd/xenpmd.c
  41. +++ b/tools/xenpmd/xenpmd.c
  42. @@ -40,6 +40,7 @@
  43. #include <unistd.h>
  44. #include <sys/stat.h>
  45. #include <xenstore.h>
  46. +#include <assert.h>
  47. /* #define RUN_STANDALONE */
  48. #define RUN_IN_SIMULATE_MODE
  49. @@ -345,18 +346,17 @@ void write_ulong_lsb_first(char *temp_val, unsigned long val)
  50. void write_battery_info_to_xenstore(struct battery_info *info)
  51. {
  52. char val[1024], string_info[256];
  53. + unsigned int len;
  54. xs_mkdir(xs, XBT_NULL, "/pm");
  55. memset(val, 0, 1024);
  56. memset(string_info, 0, 256);
  57. /* write 9 dwords (so 9*4) + length of 4 strings + 4 null terminators */
  58. - snprintf(val, 3, "%02x",
  59. - (unsigned int)(9*4 +
  60. - strlen(info->model_number) +
  61. - strlen(info->serial_number) +
  62. - strlen(info->battery_type) +
  63. - strlen(info->oem_info) + 4));
  64. + len = 9 * 4 + strlen(info->model_number) + strlen(info->serial_number) +
  65. + strlen(info->battery_type) + strlen(info->oem_info) + 4;
  66. + assert(len < 255);
  67. + snprintf(val, 3, "%02x", len);
  68. write_ulong_lsb_first(val+2, info->present);
  69. write_ulong_lsb_first(val+10, info->design_capacity);
  70. write_ulong_lsb_first(val+18, info->last_full_capacity);