Hacker News new | past | comments | ask | show | jobs | submit login

This is broken:

  .incbin "string_blob.txt"
  ...

  printf("%s\n", string_blob);
Text files don't have to have a NUL termination. The proper way to embed data with the .incbin directive is to add a label after the file and use that directly for pointer arithmetic or compute the size with another assembly directive.



Couldn't you follow up the .incbin statement with a .const 0 or something similar?


In this case it works because the author explicitly put a NUL at the end of the string in the text file. I don't think the author was trying to suggest that you can do this with arbitrary data.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: