From: clubley@remove_me.eisner.decus.org-Earth.UFP   
      
   On 2025-08-15, Chris Townley wrote:   
   > On 15/08/2025 18:33, Simon Clubley wrote:   
   >>   
   >> strncpy() makes more sense when you realise that its original purpose   
   >> was to fill fixed-size fields in a record with data and to clear the   
   >> rest of the field if the source data was smaller than the field size.   
   >>   
   >> BTW, after using strncpy(), my code always unconditionally places   
   >> a 0x00 in the final byte of the buffer "just in case :-)".   
   >>   
   >   
   > That wouldn't be good if you are filling part of a record!   
   >   
      
   Yeah, but I'm not using it for that. :-)   
      
   I wish that all modern languages had dynamically allocated string   
   support so you would not have to worry about this.   
      
   Even when they do, sometimes they still manage to mess up the   
   implementation. For example, in C++, "[]" is an unchecked   
   operator and you have to use at() to get bounds checking on   
   strings.   
      
   It would have been far better if "[]" was the bounds checked   
   operator and you had to use at() to get unchecked indexing for   
   those rare cases you needed some less overhead for performance   
   reasons.   
      
   Simon.   
      
   --   
   Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP   
   Walking destinations on a map are further away than they appear.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|