Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Code Reviews

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

71%
+3 −0
Code Reviews Counting number of assignments that a `fscanf` format strings implies

Just looking at your code, I think you'll need to look at a few nasties in scan sets: %[^]%a-z] stops at the second ], not the first, for example, and I think your code would misconstrue the %a ...

posted 3y ago by Mythical Programmer‭  ·  edited 3y ago by Mythical Programmer‭

Answer
#5: Post edited by user avatar Mythical Programmer‭ · 2020-11-01T05:44:44Z (over 3 years ago)
The two mismatched double-character length modifiers should have different sequences hl and lh
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • I think your code would accept `%hld` or `%hlu` as valid (whereas `%hhd` and `%llu` are valid — it should be two of the same length modifier). That's one specific case of the more general comment:
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • I think your code would accept `%hld` or `%lhu` as valid (whereas `%hhd` and `%llu` are valid — it should be two of the same length modifier). That's one specific case of the more general comment:
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
#4: Post edited by user avatar Mythical Programmer‭ · 2020-10-27T23:40:01Z (over 3 years ago)
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • I think your code would accept `%hld` or `%hlu` as valid (whereas `%hhd` and `%llu` are valid — it should be two of the same length modifier).
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • I think your code would accept `%hld` or `%hlu` as valid (whereas `%hhd` and `%llu` are valid — it should be two of the same length modifier). That's one specific case of the more general comment:
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
#3: Post edited by user avatar Mythical Programmer‭ · 2020-10-27T23:38:44Z (over 3 years ago)
Note about %hld etc.
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • I think your code would accept `%hld` or `%hlu` as valid (whereas `%hhd` and `%llu` are valid — it should be two of the same length modifier).
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
#2: Post edited by user avatar Mythical Programmer‭ · 2020-10-27T23:35:29Z (over 3 years ago)
Remove an unnecessary `%` in the second complex scan set.
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[%a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
  • Just looking at your code, I think you'll need to look at a few nasties in scan sets:
  • * `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
  • * Likewise `%[]%[a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.
  • You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).
  • You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).
  • You are not validating the format — which is OK, as long as you know that's what you're (not) doing.
#1: Initial revision by user avatar Mythical Programmer‭ · 2020-10-27T22:50:26Z (over 3 years ago)
Just looking at your code, I think you'll need to look at a few nasties in scan sets:

* `%[^]%a-z]` stops at the second `]`, not the first, for example, and I think your code would misconstrue the `%a` as a conversion rather than part of the scan set.
* Likewise `%[]%[%a-z]`; the one scan set there stops at the second `]`, but your code would count two scan sets, I believe.

You also need to know about `%n` (it's a conversion specifier, but it doesn't get counted). You've removed it from the list of conversion specifiers, so you may be OK with that (but your testing should test it).

You'll need to worry about suppressed conversions `%23*f` (which don't get counted either).

You are not validating the format — which is OK, as long as you know that's what you're (not) doing.