Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue #8251 ospaths.isAbsolute: out of bound errors #8291

Merged
merged 3 commits into from
Jul 13, 2018

Conversation

timotheecour
Copy link
Member

No description provided.

(len > 1 and path[0] in {'a'..'z', 'A'..'Z'} and path[1] == ':')
elif defined(macos):
result = path.len > 0 and path[0] != ':'
result = path[0] != ':'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be path.len == 0 or path[0] != ':', maybe.

Copy link
Member Author

@timotheecour timotheecour Jul 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • actually or is not the right thing since empty path should not be absolute
  • however I'm already checking for len=0 at function top-level
  • just found another preexisting bug which my latest commit fixes: the condition here should be negated! ":" would be absolute on macos (given that ":" meant the new "/" separator); => actually upon reading more I found this https://perldoc.perl.org/File/Spec/Mac.html and added that as reference for this non-intuitive behavior; on that note, see my post https://forum.nim-lang.org/t/4039 "should we keep supporting macos? (as opposed to macosx)"

@@ -423,12 +423,22 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1".} =
## Checks whether a given `path` is absolute.
##
## On Windows, network paths are considered absolute too.
runnableExamples:
doAssert "".isAbsolute.not
doAssert nil.isAbsolute.not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There soon will be no nil for strings, don't write tests covering it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

when doslikeFileSystem:
var len = len(path)
result = (len > 0 and path[0] in {'/', '\\'}) or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fail to see how removing bounds checking helps with anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the case len=0 is already handled at the very top-level of this function

@@ -423,12 +423,22 @@ proc isAbsolute*(path: string): bool {.rtl, noSideEffect, extern: "nos$1".} =
## Checks whether a given `path` is absolute.
##
## On Windows, network paths are considered absolute too.
runnableExamples:
doAssert "".isAbsolute.not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.not is not a style we use anywhere else.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that was a workaround after hitting that bug: #8300 ; but I've fixed it to doAssert(not condition)

@timotheecour
Copy link
Member Author

PTAL

@timotheecour timotheecour force-pushed the ps_isAbsolute branch 2 times, most recently from 985f05d to 7c273f3 Compare July 12, 2018 21:38
@Varriount Varriount merged commit 40f44a0 into nim-lang:devel Jul 13, 2018
@timotheecour timotheecour deleted the ps_isAbsolute branch July 13, 2018 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants